KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gendrill_excellon_writer.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018 Jean_Pierre Charras <jp.charras at wanadoo.fr>
5 * Copyright (C) 2015 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
26
27
33
34#include <plotters/plotter.h>
35#include <string_utils.h>
36#include <macros.h>
37#include <pcb_edit_frame.h>
38#include <build_version.h>
39#include <math/util.h> // for KiROUND
40#include <trigo.h>
41
42#include <pcbplot.h>
43#include <board.h>
46#include <reporter.h>
47#include <gbr_metadata.h>
48
49#include <fmt/format.h>
50
51
52// Oblong holes can be drilled by a "canned slot" command (G85) or a routing command
53// a linear routing command (G01) is perhaps more usual for drill files
54//
55// set m_useRouteModeForOval to false to use a canned slot hole (old way)
56// set m_useRouteModeForOval to true (preferred mode) to use a linear routed hole (new way)
57
58
60 : GENDRILL_WRITER_BASE( aPcb )
61{
62 m_file = nullptr;
64 m_conversionUnits = 0.0001;
65 m_mirror = false;
66 m_merge_PTH_NPTH = false;
67 m_minimalHeader = false;
70 m_mantissaLenght = 3; // suitable to print coordinates in mm
71}
72
73
74bool EXCELLON_WRITER::CreateDrillandMapFilesSet( const wxString& aPlotDirectory, bool aGenDrill,
75 bool aGenMap, REPORTER * aReporter )
76{
77 bool success = true;
78 wxFileName fn;
79 wxString msg;
80
81 std::vector<DRILL_SPAN> hole_sets = getUniqueLayerPairs();
82
83 if( !m_merge_PTH_NPTH )
84 hole_sets.emplace_back( F_Cu, B_Cu, false, true );
85
86 for( std::vector<DRILL_SPAN>::const_iterator it = hole_sets.begin();
87 it != hole_sets.end(); ++it )
88 {
89 const DRILL_SPAN& span = *it;
90 bool doing_npth = m_merge_PTH_NPTH ? false : span.m_IsNonPlatedFile;
91
92 buildHolesList( span, doing_npth );
93
94 // The file is created if it has holes, or if it is the non plated drill file to be
95 // sure the NPTH file is up to date in separate files mode.
96 // Also a PTH drill/map file is always created, to be sure at least one plated hole
97 // drill file is created (do not create any PTH drill file can be seen as not working
98 // drill generator).
99 if( getHolesCount() > 0 || doing_npth || span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) )
100 {
101 fn = getDrillFileName( span, doing_npth, m_merge_PTH_NPTH );
102 fn.SetPath( aPlotDirectory );
103
104 if( aGenDrill )
105 {
106 wxString fullFilename = fn.GetFullPath();
107
108 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
109
110 if( file == nullptr )
111 {
112 if( aReporter )
113 {
114 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
115 aReporter->Report( msg, RPT_SEVERITY_ERROR );
116 success = false;
117 }
118
119 break;
120 }
121 else
122 {
123 if( aReporter )
124 {
125 msg.Printf( _( "Created file '%s'" ), fullFilename );
126 aReporter->Report( msg, RPT_SEVERITY_ACTION );
127 }
128 }
129
130 TYPE_FILE file_type = TYPE_FILE::PTH_FILE;
131
132 if( span.Pair() == DRILL_LAYER_PAIR( F_Cu, B_Cu ) && !span.m_IsBackdrill )
133 {
134 if( m_merge_PTH_NPTH )
135 file_type = TYPE_FILE::MIXED_FILE;
136 else if( doing_npth )
137 file_type = TYPE_FILE::NPTH_FILE;
138 }
139 else if( span.m_IsBackdrill )
140 {
141 file_type = TYPE_FILE::NPTH_FILE;
142 }
143
144 bool wroteDrillFile = false;
145
146 try
147 {
148 createDrillFile( file, span, file_type );
149 wroteDrillFile = true;
150 }
151 catch( ... ) // Capture fmt::print exception on write issues
152 {
153 fclose( file );
154 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
155 aReporter->Report( msg, RPT_SEVERITY_ERROR );
156 success = false;
157 }
158
159 if( wroteDrillFile && span.m_IsBackdrill && getHolesCount() > 0 )
160 {
161 if( !writeBackdrillLayerPairFile( aPlotDirectory, aReporter, span ) )
162 {
163 success = false;
164 break;
165 }
166 }
167
168 if( wroteDrillFile )
169 AddCreatedFile( fullFilename );
170 }
171 }
172 }
173
174 if( aGenMap )
175 success &= CreateMapFilesSet( aPlotDirectory, aReporter );
176
177 if( aReporter )
178 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
179
180 return success;
181}
182
183
185{
186 // Hole attributes are comments (lines starting by ';') in the drill files
187 // For tools (file header), they are similar to X2 apertures attributes.
188 // for attributes added in coordinate list, they are just comments.
189 if( !m_minimalHeader )
190 {
191 switch( aAttribute )
192 {
194 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
195 break;
196
198 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
199 break;
200
202 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,BackDrill\n" );
203 break;
204
206 //case HOLE_ATTRIBUTE::HOLE_PAD_CASTELLATED:
207 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
208 break;
209
211 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
212 break;
213
215 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
216 break;
217
219 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
220 break;
221
223 fmt::print( m_file, "{}", "; #@! TD\n" );
224 break;
225 }
226 }
227}
228
229
230int EXCELLON_WRITER::createDrillFile( FILE* aFile, const DRILL_SPAN& aSpan,
231 TYPE_FILE aHolesType, bool aTagBackdrillHit )
232{
233 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
234 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
236
237 m_file = aFile;
238
239 int diam, holes_count;
240 int x0, y0, xf, yf, xc, yc;
241 double xt, yt;
242 char line[1024];
243
244 writeEXCELLONHeader( aSpan, aHolesType );
245
246 holes_count = 0;
247
248 /* Write the tool list */
249 for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
250 {
251 DRILL_TOOL& tool_descr = m_toolListBuffer[ii];
252
253#if USE_ATTRIB_FOR_HOLES
255#endif
256 fmt::print( m_file, "T{}C{:.{}f}\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits, m_mantissaLenght );
257
258 if( !m_minimalHeader )
259 {
260 if( tool_descr.m_IsBackdrill )
261 {
262 auto formatStub = [&]( int aStubLength )
263 {
264 double stubMM = pcbIUScale.IUTomm( aStubLength );
265 double stubInches = stubMM / 25.4;
266 wxString tmp = fmt::format( "{:.3f}mm ({:.4f}\")", stubMM, stubInches );
267 return tmp;
268 };
269
270 wxString comment = wxT( "; Backdrill" );
271
272 if( tool_descr.m_MinStubLength.has_value() )
273 {
274 comment += wxT( " stub " );
275 comment += formatStub( *tool_descr.m_MinStubLength );;
276
277 if( tool_descr.m_MaxStubLength.has_value()
278 && tool_descr.m_MaxStubLength != tool_descr.m_MinStubLength )
279 {
280 comment += wxT( " to " );
281 comment += formatStub( *tool_descr.m_MaxStubLength );;
282 }
283 }
284
285 if( tool_descr.m_HasPostMachining )
286 comment += wxT( ", post-machining" );
287
288 comment += wxT( "\n" );
289 fmt::print( m_file, "{}", TO_UTF8( comment ) );
290 }
291 else if( tool_descr.m_HasPostMachining )
292 {
293 fmt::print( m_file, "{}", "; Post-machining\n" );
294 }
295 }
296 }
297
298 fmt::print( m_file, "{}", "%\n" ); // End of header info
299 fmt::print( m_file, "{}", "G90\n" ); // Absolute mode
300 fmt::print( m_file, "{}", "G05\n" ); // Drill mode
301
302 /* Read the hole list and generate data for normal holes (oblong
303 * holes will be created later) */
304 int tool_reference = -2;
305
306 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
307 {
308 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
309
310 if( hole_descr.m_Hole_Shape )
311 continue; // oblong holes will be created later
312
313 if( tool_reference != hole_descr.m_Tool_Reference )
314 {
315 tool_reference = hole_descr.m_Tool_Reference;
316 fmt::print( m_file, "T{}\n", tool_reference );
317 }
318
319 x0 = hole_descr.m_Hole_Pos.x - m_offset.x;
320 y0 = hole_descr.m_Hole_Pos.y - m_offset.y;
321
322 if( !m_mirror )
323 y0 *= -1;
324
325 xt = x0 * m_conversionUnits;
326 yt = y0 * m_conversionUnits;
327 writeHoleComments( hole_descr, aTagBackdrillHit );
328 writeCoordinates( line, sizeof( line ), xt, yt );
329
330 fmt::print( m_file, "{}", line );
331 holes_count++;
332 }
333
334 /* Read the hole list and generate data for oblong holes
335 */
336 tool_reference = -2; // set to a value not used for
337 // m_holeListBuffer[ii].m_Tool_Reference
338
339 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
340 {
341 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
342
343 if( hole_descr.m_Hole_Shape == 0 )
344 continue; // wait for oblong holes
345
346 if( tool_reference != hole_descr.m_Tool_Reference )
347 {
348 tool_reference = hole_descr.m_Tool_Reference;
349 fmt::print( m_file, "T{}\n", tool_reference );
350 }
351
352 diam = std::min( hole_descr.m_Hole_Size.x, hole_descr.m_Hole_Size.y );
353
354 if( diam == 0 )
355 continue;
356
357 /* Compute the hole coordinates: */
358 xc = x0 = xf = hole_descr.m_Hole_Pos.x - m_offset.x;
359 yc = y0 = yf = hole_descr.m_Hole_Pos.y - m_offset.y;
360
361 /* Compute the start and end coordinates for the shape */
362 if( hole_descr.m_Hole_Size.x < hole_descr.m_Hole_Size.y )
363 {
364 int delta = ( hole_descr.m_Hole_Size.y - hole_descr.m_Hole_Size.x ) / 2;
365 y0 -= delta;
366 yf += delta;
367 }
368 else
369 {
370 int delta = ( hole_descr.m_Hole_Size.x - hole_descr.m_Hole_Size.y ) / 2;
371 x0 -= delta;
372 xf += delta;
373 }
374
375 RotatePoint( &x0, &y0, xc, yc, hole_descr.m_Hole_Orient );
376 RotatePoint( &xf, &yf, xc, yc, hole_descr.m_Hole_Orient );
377
378 if( !m_mirror )
379 {
380 y0 *= -1;
381 yf *= -1;
382 }
383
384 xt = x0 * m_conversionUnits;
385 yt = y0 * m_conversionUnits;
386 writeHoleComments( hole_descr, aTagBackdrillHit );
387
389 fmt::print( m_file, "{}", "G00" ); // Select the routing mode
390
391 writeCoordinates( line, sizeof( line ), xt, yt );
392
394 {
395 /* remove the '\n' from end of line, because we must add the "G85"
396 * command to the line: */
397 for( int kk = 0; line[kk] != 0; kk++ )
398 {
399 if( line[kk] < ' ' )
400 line[kk] = 0;
401 }
402
403 fmt::print( m_file, "{}", line );
404 fmt::print( m_file, "{}", "G85" ); // add the "G85" command
405 }
406 else
407 {
408 fmt::print( m_file, "{}", line );
409 fmt::print( m_file, "{}", "M15\nG01" ); // tool down and linear routing from last coordinates
410 }
411
412 xt = xf * m_conversionUnits;
413 yt = yf * m_conversionUnits;
414 writeCoordinates( line, sizeof( line ), xt, yt );
415
416 fmt::print( m_file, "{}",line );
417
419 fmt::print( m_file, "{}", "M16\n" ); // Tool up (end routing)
420
421 fmt::print( m_file, "{}", "G05\n" ); // Select drill mode
422 holes_count++;
423 }
424
426
427 return holes_count;
428}
429
430
431void EXCELLON_WRITER::SetFormat( bool aMetric, ZEROS_FMT aZerosFmt, int aLeftDigits,
432 int aRightDigits )
433{
434 m_unitsMetric = aMetric;
435 m_zeroFormat = aZerosFmt;
436
437 /* Set conversion scale depending on drill file units */
438 if( m_unitsMetric )
439 m_conversionUnits = 1.0 / pcbIUScale.IU_PER_MM; // EXCELLON units = mm
440 else
441 m_conversionUnits = 0.001 / pcbIUScale.IU_PER_MILS; // EXCELLON units = in
442
443 // Set the zero counts. if aZerosFmt == DECIMAL_FORMAT, these values
444 // will be set, but not used.
445 if( aLeftDigits <= 0 )
446 aLeftDigits = m_unitsMetric ? 3 : 2;
447
448 if( aRightDigits <= 0 )
449 aRightDigits = m_unitsMetric ? 3 : 4;
450
451 m_precision.m_Lhs = aLeftDigits;
452 m_precision.m_Rhs = aRightDigits;
453}
454
455
456void EXCELLON_WRITER::writeCoordinates( char* aLine, size_t aLineSize, double aCoordX,
457 double aCoordY )
458{
459 wxString xs, ys;
460 int xpad = m_precision.m_Lhs + m_precision.m_Rhs;
461 int ypad = xpad;
462
463 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
464 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
465 // in DECIMAL_FORMAT we could use more digits.
466
467 switch( m_zeroFormat )
468 {
469 default:
470 case DECIMAL_FORMAT:
471 /* In Excellon files, resolution is 1/1000 mm or 1/10000 inch (0.1 mil)
472 * Although in decimal format, Excellon specifications do not specify
473 * clearly the resolution. However it seems to be usually 1/1000mm or 0.1 mil
474 * like in non decimal formats, so we trunk coordinates to m_mantissaLenght in mantissa
475 * Decimal format just prohibit useless leading 0:
476 * 0.45 or .45 is right, but 00.54 is incorrect.
477 */
478 xs = fmt::format( "{:.{}f}", aCoordX, m_mantissaLenght );
479 ys = fmt::format( "{:.{}f}", aCoordY, m_mantissaLenght );
480
481 //Remove useless trailing 0
482 while( xs.Last() == '0' )
483 xs.RemoveLast();
484
485 if( xs.Last() == '.' ) // however keep a trailing 0 after the floating point separator
486 xs << '0';
487
488 while( ys.Last() == '0' )
489 ys.RemoveLast();
490
491 if( ys.Last() == '.' )
492 ys << '0';
493
494 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
495 break;
496
497 case SUPPRESS_LEADING:
498 for( int i = 0; i< m_precision.m_Rhs; i++ )
499 {
500 aCoordX *= 10; aCoordY *= 10;
501 }
502
503 std::snprintf( aLine, aLineSize, "X%dY%d\n", KiROUND( aCoordX ), KiROUND( aCoordY ) );
504 break;
505
507 {
508 for( int i = 0; i < m_precision.m_Rhs; i++ )
509 {
510 aCoordX *= 10;
511 aCoordY *= 10;
512 }
513
514 if( aCoordX < 0 )
515 xpad++;
516
517 if( aCoordY < 0 )
518 ypad++;
519
520 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
521 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
522
523 size_t j = xs.Len() - 1;
524
525 while( xs[j] == '0' && j )
526 xs.Truncate( j-- );
527
528 j = ys.Len() - 1;
529
530 while( ys[j] == '0' && j )
531 ys.Truncate( j-- );
532
533 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
534 break;
535 }
536
537 case KEEP_ZEROS:
538 for( int i = 0; i< m_precision.m_Rhs; i++ )
539 {
540 aCoordX *= 10; aCoordY *= 10;
541 }
542
543 if( aCoordX < 0 )
544 xpad++;
545
546 if( aCoordY < 0 )
547 ypad++;
548
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 ) );
552 break;
553 }
554}
555
556
558{
559 fmt::print( m_file, "{}", "M48\n" ); // The beginning of a header
560
561 if( !m_minimalHeader )
562 {
563 // The next lines in EXCELLON files are comments:
564 wxString msg;
565 msg << wxT( "KiCad " ) << GetBuildVersion();
566
567 fmt::print( m_file, "; DRILL file {} date {}\n",
569 msg = wxT( "; FORMAT={" );
570
571 // Print precision:
572 // Note in decimal format the precision is not used.
573 // the floating point notation has higher priority than the precision.
575 msg << m_precision.GetPrecisionString();
576 else
577 msg << wxT( "-:-" ); // in decimal format the precision is irrelevant
578
579 msg << wxT( "/ absolute / " );
580 msg << ( m_unitsMetric ? wxT( "metric" ) : wxT( "inch" ) );
581
582 /* Adding numbers notation format.
583 * this is same as m_Choice_Zeros_Format strings, but NOT translated
584 * because some EXCELLON parsers do not like non ASCII values
585 * so we use ONLY English (ASCII) strings.
586 * if new options are added in m_Choice_Zeros_Format, they must also
587 * be added here
588 */
589 msg << wxT( " / " );
590
591 const wxString zero_fmt[4] =
592 {
593 wxT( "decimal" ),
594 wxT( "suppress leading zeros" ),
595 wxT( "suppress trailing zeros" ),
596 wxT( "keep zeros" )
597 };
598
599 msg << zero_fmt[m_zeroFormat] << wxT( "}\n" );
600 fmt::print( m_file, "{}", TO_UTF8( msg ) );
601
602 // add the structured comment TF.CreationDate:
603 // The attribute value must conform to the full version of the ISO 8601
605 fmt::print( m_file, "{}", TO_UTF8( msg ) );
606
607 // Add the application name that created the drill file
608 msg = wxT( "; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
609 msg << GetBuildVersion() << wxT( "\n" );
610 fmt::print( m_file, "{}", TO_UTF8( msg ) );
611
612 // Add the standard X2 FileFunction for drill files
613 // TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH]
614 msg = BuildFileFunctionAttributeString( aSpan, aHolesType , true ) + wxT( "\n" );
615 fmt::print( m_file, "{}", TO_UTF8( msg ) );
616
617 fmt::print( m_file, "{}", "FMAT,2\n" ); // Use Format 2 commands (version used since 1979)
618 }
619
620 fmt::print( m_file, "{}", m_unitsMetric ? "METRIC" : "INCH" );
621
622 switch( m_zeroFormat )
623 {
624 case DECIMAL_FORMAT:
625 fmt::print( m_file, "{}", "\n" );
626 break;
627
628 case SUPPRESS_LEADING:
629 fmt::print( m_file, "{}", ",TZ\n" );
630 break;
631
633 fmt::print( m_file, "{}", ",LZ\n" );
634 break;
635
636 case KEEP_ZEROS:
637 // write nothing, but TZ is acceptable when all zeros are kept
638 fmt::print( m_file, "{}", "\n" );
639 break;
640 }
641}
642
643
645{
646 // add if minimal here
647 fmt::print( m_file, "{}", "M30\n" );
648 fclose( m_file );
649}
650
651
653{
654 wxFileName fn = m_pcb->GetFileName();
655 wxString extend;
656
657 extend << wxT( "-" )
658 << wxString::FromUTF8( layerPairName( aSpan.Pair() ).c_str() )
659 << wxT( "-backdrill" );
660
661 fn.SetName( fn.GetName() + extend );
662 fn.SetExt( m_drillFileExtension );
663
664 return fn;
665}
666
667
668bool EXCELLON_WRITER::writeBackdrillLayerPairFile( const wxString& aPlotDirectory,
669 REPORTER* aReporter, const DRILL_SPAN& aSpan )
670{
671 wxFileName fn = getBackdrillLayerPairFileName( aSpan );
672 fn.SetPath( aPlotDirectory );
673
674 wxString fullFilename = fn.GetFullPath();
675 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
676
677 if( file == nullptr )
678 {
679 if( aReporter )
680 {
681 wxString msg;
682 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
683 aReporter->Report( msg, RPT_SEVERITY_ERROR );
684 }
685
686 return false;
687 }
688 else if( aReporter )
689 {
690 wxString msg;
691 msg.Printf( _( "Created file '%s'" ), fullFilename );
692 aReporter->Report( msg, RPT_SEVERITY_ACTION );
693 }
694
695 try
696 {
697 createDrillFile( file, aSpan, TYPE_FILE::NPTH_FILE, true );
698 }
699 catch( ... )
700 {
701 fclose( file );
702
703 if( aReporter )
704 {
705 wxString msg;
706 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
707 aReporter->Report( msg, RPT_SEVERITY_ERROR );
708 }
709
710 return false;
711 }
712
713 AddCreatedFile( fullFilename );
714
715 return true;
716}
717
718void EXCELLON_WRITER::writeHoleComments( const HOLE_INFO& aHole, bool aTagBackdrillHit )
719{
720 if( aTagBackdrillHit && aHole.m_IsBackdrill )
721 fmt::print( m_file, "{}", "; backdrill\n" );
722
725 wxT( "front" ) );
726
729 wxT( "back" ) );
730}
731
732
734 int aSizeIU, int aDepthIU, int aAngleDeciDegree,
735 const wxString& aSideLabel )
736{
739 {
740 return;
741 }
742
743 wxString comment;
744 comment << wxT( "; Post-machining " ) << aSideLabel << wxT( " " )
745 << ( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ? wxT( "countersink" )
746 : wxT( "counterbore" ) );
747
748 wxString sizeStr = formatLinearValue( aSizeIU );
749
750 if( !sizeStr.IsEmpty() )
751 comment << wxT( " dia " ) << sizeStr;
752
753 wxString depthStr = formatLinearValue( aDepthIU );
754
755 if( !depthStr.IsEmpty() )
756 comment << wxT( " depth " ) << depthStr;
757
758 if( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK && aAngleDeciDegree > 0 )
759 {
760 double angle = aAngleDeciDegree / 10.0;
761 wxString angleStr;
762
763 if( ( aAngleDeciDegree % 10 ) == 0 )
764 angleStr = fmt::format( "{:.0f}deg", angle );
765 else
766 angleStr = fmt::format( "{:.1f}deg", angle );
767
768 comment << wxT( " angle " ) << angleStr;
769 }
770
771 comment << wxT( "\n" );
772 fmt::print( m_file, "{}", TO_UTF8( comment ) );
773}
774
775
776wxString EXCELLON_WRITER::formatLinearValue( int aValueIU ) const
777{
778 if( aValueIU <= 0 )
779 return wxString();
780
781 double converted = aValueIU * m_conversionUnits;
782 wxString value;
783 value = fmt::format( "{:.{}f}", converted, m_mantissaLenght );
784 value << ( m_unitsMetric ? wxT( "mm" ) : wxT( "in" ) );
785
786 return value;
787}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:995
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
std::optional< int > m_MinStubLength
HOLE_ATTRIBUTE m_HoleAttribute
std::optional< int > m_MaxStubLength
void SetFormat(bool aMetric, ZEROS_FMT aZerosFmt=DECIMAL_FORMAT, int aLeftDigits=0, int aRightDigits=0)
Initialize internal parameters to match the given format.
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.
wxFileName getBackdrillLayerPairFileName(const DRILL_SPAN &aSpan) const
wxString formatLinearValue(int aValueIU) const
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)
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.
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...
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).
PAD_DRILL_POST_MACHINING_MODE m_FrontPostMachining
PAD_DRILL_POST_MACHINING_MODE m_BackPostMachining
EDA_ANGLE m_Hole_Orient
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:102
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.
Definition reporter.h:121
HOLE_ATTRIBUTE
Definition drill_span.h:36
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
Definition drill_span.h:48
#define _(s)
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
Handle special data (items attributes) during plot.
@ GBR_NC_STRING_FORMAT_NCDRILL
Classes used in drill files, map files and report files generation.
static const std::string DrillFileExtension
@ B_Cu
Definition layer_ids.h:61
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
PAD_DRILL_POST_MACHINING_MODE
Definition padstack.h:75
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_INFO
@ RPT_SEVERITY_ACTION
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
Definition drill_span.h:92
bool m_IsNonPlatedFile
Definition drill_span.h:130
bool m_IsBackdrill
Definition drill_span.h:129
int delta
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 trigo.cpp:225
Definition of file extensions used in Kicad.