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 }
169 }
170
171 if( aGenMap )
172 success &= CreateMapFilesSet( aPlotDirectory, aReporter );
173
174 if( aReporter )
175 aReporter->ReportTail( _( "Done." ), RPT_SEVERITY_INFO );
176
177 return success;
178}
179
180
182{
183 // Hole attributes are comments (lines starting by ';') in the drill files
184 // For tools (file header), they are similar to X2 apertures attributes.
185 // for attributes added in coordinate list, they are just comments.
186 if( !m_minimalHeader )
187 {
188 switch( aAttribute )
189 {
191 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ViaDrill\n" );
192 break;
193
195 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,Buried,ViaDrill\n" );
196 break;
197
199 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,BackDrill\n" );
200 break;
201
203 //case HOLE_ATTRIBUTE::HOLE_PAD_CASTELLATED:
204 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill\n" );
205 break;
206
208 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,CastelletedDrill\n" );
209 break;
210
212 fmt::print( m_file, "{}", "; #@! TA.AperFunction,Plated,PTH,ComponentDrill,PressFit\n" );
213 break;
214
216 fmt::print( m_file, "{}", "; #@! TA.AperFunction,NonPlated,NPTH,ComponentDrill\n" );
217 break;
218
220 fmt::print( m_file, "{}", "; #@! TD\n" );
221 break;
222 }
223 }
224}
225
226
227int EXCELLON_WRITER::createDrillFile( FILE* aFile, const DRILL_SPAN& aSpan,
228 TYPE_FILE aHolesType, bool aTagBackdrillHit )
229{
230 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
231 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
233
234 m_file = aFile;
235
236 int diam, holes_count;
237 int x0, y0, xf, yf, xc, yc;
238 double xt, yt;
239 char line[1024];
240
241 writeEXCELLONHeader( aSpan, aHolesType );
242
243 holes_count = 0;
244
245 /* Write the tool list */
246 for( unsigned ii = 0; ii < m_toolListBuffer.size(); ii++ )
247 {
248 DRILL_TOOL& tool_descr = m_toolListBuffer[ii];
249
250#if USE_ATTRIB_FOR_HOLES
252#endif
253 fmt::print( m_file, "T{}C{:.{}f}\n", ii + 1, tool_descr.m_Diameter * m_conversionUnits, m_mantissaLenght );
254
255 if( !m_minimalHeader )
256 {
257 if( tool_descr.m_IsBackdrill )
258 {
259 auto formatStub = [&]( int aStubLength )
260 {
261 double stubMM = pcbIUScale.IUTomm( aStubLength );
262 double stubInches = stubMM / 25.4;
263 wxString tmp = fmt::format( "{:.3f}mm ({:.4f}\")", stubMM, stubInches );
264 return tmp;
265 };
266
267 wxString comment = wxT( "; Backdrill" );
268
269 if( tool_descr.m_MinStubLength.has_value() )
270 {
271 comment += wxT( " stub " );
272 comment += formatStub( *tool_descr.m_MinStubLength );;
273
274 if( tool_descr.m_MaxStubLength.has_value()
275 && tool_descr.m_MaxStubLength != tool_descr.m_MinStubLength )
276 {
277 comment += wxT( " to " );
278 comment += formatStub( *tool_descr.m_MaxStubLength );;
279 }
280 }
281
282 if( tool_descr.m_HasPostMachining )
283 comment += wxT( ", post-machining" );
284
285 comment += wxT( "\n" );
286 fmt::print( m_file, "{}", TO_UTF8( comment ) );
287 }
288 else if( tool_descr.m_HasPostMachining )
289 {
290 fmt::print( m_file, "{}", "; Post-machining\n" );
291 }
292 }
293 }
294
295 fmt::print( m_file, "{}", "%\n" ); // End of header info
296 fmt::print( m_file, "{}", "G90\n" ); // Absolute mode
297 fmt::print( m_file, "{}", "G05\n" ); // Drill mode
298
299 /* Read the hole list and generate data for normal holes (oblong
300 * holes will be created later) */
301 int tool_reference = -2;
302
303 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
304 {
305 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
306
307 if( hole_descr.m_Hole_Shape )
308 continue; // oblong holes will be created later
309
310 if( tool_reference != hole_descr.m_Tool_Reference )
311 {
312 tool_reference = hole_descr.m_Tool_Reference;
313 fmt::print( m_file, "T{}\n", tool_reference );
314 }
315
316 x0 = hole_descr.m_Hole_Pos.x - m_offset.x;
317 y0 = hole_descr.m_Hole_Pos.y - m_offset.y;
318
319 if( !m_mirror )
320 y0 *= -1;
321
322 xt = x0 * m_conversionUnits;
323 yt = y0 * m_conversionUnits;
324 writeHoleComments( hole_descr, aTagBackdrillHit );
325 writeCoordinates( line, sizeof( line ), xt, yt );
326
327 fmt::print( m_file, "{}", line );
328 holes_count++;
329 }
330
331 /* Read the hole list and generate data for oblong holes
332 */
333 tool_reference = -2; // set to a value not used for
334 // m_holeListBuffer[ii].m_Tool_Reference
335
336 for( unsigned ii = 0; ii < m_holeListBuffer.size(); ii++ )
337 {
338 HOLE_INFO& hole_descr = m_holeListBuffer[ii];
339
340 if( hole_descr.m_Hole_Shape == 0 )
341 continue; // wait for oblong holes
342
343 if( tool_reference != hole_descr.m_Tool_Reference )
344 {
345 tool_reference = hole_descr.m_Tool_Reference;
346 fmt::print( m_file, "T{}\n", tool_reference );
347 }
348
349 diam = std::min( hole_descr.m_Hole_Size.x, hole_descr.m_Hole_Size.y );
350
351 if( diam == 0 )
352 continue;
353
354 /* Compute the hole coordinates: */
355 xc = x0 = xf = hole_descr.m_Hole_Pos.x - m_offset.x;
356 yc = y0 = yf = hole_descr.m_Hole_Pos.y - m_offset.y;
357
358 /* Compute the start and end coordinates for the shape */
359 if( hole_descr.m_Hole_Size.x < hole_descr.m_Hole_Size.y )
360 {
361 int delta = ( hole_descr.m_Hole_Size.y - hole_descr.m_Hole_Size.x ) / 2;
362 y0 -= delta;
363 yf += delta;
364 }
365 else
366 {
367 int delta = ( hole_descr.m_Hole_Size.x - hole_descr.m_Hole_Size.y ) / 2;
368 x0 -= delta;
369 xf += delta;
370 }
371
372 RotatePoint( &x0, &y0, xc, yc, hole_descr.m_Hole_Orient );
373 RotatePoint( &xf, &yf, xc, yc, hole_descr.m_Hole_Orient );
374
375 if( !m_mirror )
376 {
377 y0 *= -1;
378 yf *= -1;
379 }
380
381 xt = x0 * m_conversionUnits;
382 yt = y0 * m_conversionUnits;
383 writeHoleComments( hole_descr, aTagBackdrillHit );
384
386 fmt::print( m_file, "{}", "G00" ); // Select the routing mode
387
388 writeCoordinates( line, sizeof( line ), xt, yt );
389
391 {
392 /* remove the '\n' from end of line, because we must add the "G85"
393 * command to the line: */
394 for( int kk = 0; line[kk] != 0; kk++ )
395 {
396 if( line[kk] < ' ' )
397 line[kk] = 0;
398 }
399
400 fmt::print( m_file, "{}", line );
401 fmt::print( m_file, "{}", "G85" ); // add the "G85" command
402 }
403 else
404 {
405 fmt::print( m_file, "{}", line );
406 fmt::print( m_file, "{}", "M15\nG01" ); // tool down and linear routing from last coordinates
407 }
408
409 xt = xf * m_conversionUnits;
410 yt = yf * m_conversionUnits;
411 writeCoordinates( line, sizeof( line ), xt, yt );
412
413 fmt::print( m_file, "{}",line );
414
416 fmt::print( m_file, "{}", "M16\n" ); // Tool up (end routing)
417
418 fmt::print( m_file, "{}", "G05\n" ); // Select drill mode
419 holes_count++;
420 }
421
423
424 return holes_count;
425}
426
427
428void EXCELLON_WRITER::SetFormat( bool aMetric, ZEROS_FMT aZerosFmt, int aLeftDigits,
429 int aRightDigits )
430{
431 m_unitsMetric = aMetric;
432 m_zeroFormat = aZerosFmt;
433
434 /* Set conversion scale depending on drill file units */
435 if( m_unitsMetric )
436 m_conversionUnits = 1.0 / pcbIUScale.IU_PER_MM; // EXCELLON units = mm
437 else
438 m_conversionUnits = 0.001 / pcbIUScale.IU_PER_MILS; // EXCELLON units = in
439
440 // Set the zero counts. if aZerosFmt == DECIMAL_FORMAT, these values
441 // will be set, but not used.
442 if( aLeftDigits <= 0 )
443 aLeftDigits = m_unitsMetric ? 3 : 2;
444
445 if( aRightDigits <= 0 )
446 aRightDigits = m_unitsMetric ? 3 : 4;
447
448 m_precision.m_Lhs = aLeftDigits;
449 m_precision.m_Rhs = aRightDigits;
450}
451
452
453void EXCELLON_WRITER::writeCoordinates( char* aLine, size_t aLineSize, double aCoordX,
454 double aCoordY )
455{
456 wxString xs, ys;
457 int xpad = m_precision.m_Lhs + m_precision.m_Rhs;
458 int ypad = xpad;
459
460 // if units are mm, the resolution is 0.001 mm (3 digits in mantissa)
461 // if units are inches, the resolution is 0.1 mil (4 digits in mantissa)
462 // in DECIMAL_FORMAT we could use more digits.
463
464 switch( m_zeroFormat )
465 {
466 default:
467 case DECIMAL_FORMAT:
468 /* In Excellon files, resolution is 1/1000 mm or 1/10000 inch (0.1 mil)
469 * Although in decimal format, Excellon specifications do not specify
470 * clearly the resolution. However it seems to be usually 1/1000mm or 0.1 mil
471 * like in non decimal formats, so we trunk coordinates to m_mantissaLenght in mantissa
472 * Decimal format just prohibit useless leading 0:
473 * 0.45 or .45 is right, but 00.54 is incorrect.
474 */
475 xs = fmt::format( "{:.{}f}", aCoordX, m_mantissaLenght );
476 ys = fmt::format( "{:.{}f}", aCoordY, m_mantissaLenght );
477
478 //Remove useless trailing 0
479 while( xs.Last() == '0' )
480 xs.RemoveLast();
481
482 if( xs.Last() == '.' ) // however keep a trailing 0 after the floating point separator
483 xs << '0';
484
485 while( ys.Last() == '0' )
486 ys.RemoveLast();
487
488 if( ys.Last() == '.' )
489 ys << '0';
490
491 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
492 break;
493
494 case SUPPRESS_LEADING:
495 for( int i = 0; i< m_precision.m_Rhs; i++ )
496 {
497 aCoordX *= 10; aCoordY *= 10;
498 }
499
500 std::snprintf( aLine, aLineSize, "X%dY%d\n", KiROUND( aCoordX ), KiROUND( aCoordY ) );
501 break;
502
504 {
505 for( int i = 0; i < m_precision.m_Rhs; i++ )
506 {
507 aCoordX *= 10;
508 aCoordY *= 10;
509 }
510
511 if( aCoordX < 0 )
512 xpad++;
513
514 if( aCoordY < 0 )
515 ypad++;
516
517 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
518 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
519
520 size_t j = xs.Len() - 1;
521
522 while( xs[j] == '0' && j )
523 xs.Truncate( j-- );
524
525 j = ys.Len() - 1;
526
527 while( ys[j] == '0' && j )
528 ys.Truncate( j-- );
529
530 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
531 break;
532 }
533
534 case KEEP_ZEROS:
535 for( int i = 0; i< m_precision.m_Rhs; i++ )
536 {
537 aCoordX *= 10; aCoordY *= 10;
538 }
539
540 if( aCoordX < 0 )
541 xpad++;
542
543 if( aCoordY < 0 )
544 ypad++;
545
546 xs.Printf( wxT( "%0*d" ), xpad, KiROUND( aCoordX ) );
547 ys.Printf( wxT( "%0*d" ), ypad, KiROUND( aCoordY ) );
548 std::snprintf( aLine, aLineSize, "X%sY%s\n", TO_UTF8( xs ), TO_UTF8( ys ) );
549 break;
550 }
551}
552
553
555{
556 fmt::print( m_file, "{}", "M48\n" ); // The beginning of a header
557
558 if( !m_minimalHeader )
559 {
560 // The next lines in EXCELLON files are comments:
561 wxString msg;
562 msg << wxT( "KiCad " ) << GetBuildVersion();
563
564 fmt::print( m_file, "; DRILL file {} date {}\n",
566 msg = wxT( "; FORMAT={" );
567
568 // Print precision:
569 // Note in decimal format the precision is not used.
570 // the floating point notation has higher priority than the precision.
572 msg << m_precision.GetPrecisionString();
573 else
574 msg << wxT( "-:-" ); // in decimal format the precision is irrelevant
575
576 msg << wxT( "/ absolute / " );
577 msg << ( m_unitsMetric ? wxT( "metric" ) : wxT( "inch" ) );
578
579 /* Adding numbers notation format.
580 * this is same as m_Choice_Zeros_Format strings, but NOT translated
581 * because some EXCELLON parsers do not like non ASCII values
582 * so we use ONLY English (ASCII) strings.
583 * if new options are added in m_Choice_Zeros_Format, they must also
584 * be added here
585 */
586 msg << wxT( " / " );
587
588 const wxString zero_fmt[4] =
589 {
590 wxT( "decimal" ),
591 wxT( "suppress leading zeros" ),
592 wxT( "suppress trailing zeros" ),
593 wxT( "keep zeros" )
594 };
595
596 msg << zero_fmt[m_zeroFormat] << wxT( "}\n" );
597 fmt::print( m_file, "{}", TO_UTF8( msg ) );
598
599 // add the structured comment TF.CreationDate:
600 // The attribute value must conform to the full version of the ISO 8601
602 fmt::print( m_file, "{}", TO_UTF8( msg ) );
603
604 // Add the application name that created the drill file
605 msg = wxT( "; #@! TF.GenerationSoftware,Kicad,Pcbnew," );
606 msg << GetBuildVersion() << wxT( "\n" );
607 fmt::print( m_file, "{}", TO_UTF8( msg ) );
608
609 // Add the standard X2 FileFunction for drill files
610 // TF.FileFunction,Plated[NonPlated],layer1num,layer2num,PTH[NPTH]
611 msg = BuildFileFunctionAttributeString( aSpan, aHolesType , true ) + wxT( "\n" );
612 fmt::print( m_file, "{}", TO_UTF8( msg ) );
613
614 fmt::print( m_file, "{}", "FMAT,2\n" ); // Use Format 2 commands (version used since 1979)
615 }
616
617 fmt::print( m_file, "{}", m_unitsMetric ? "METRIC" : "INCH" );
618
619 switch( m_zeroFormat )
620 {
621 case DECIMAL_FORMAT:
622 fmt::print( m_file, "{}", "\n" );
623 break;
624
625 case SUPPRESS_LEADING:
626 fmt::print( m_file, "{}", ",TZ\n" );
627 break;
628
630 fmt::print( m_file, "{}", ",LZ\n" );
631 break;
632
633 case KEEP_ZEROS:
634 // write nothing, but TZ is acceptable when all zeros are kept
635 fmt::print( m_file, "{}", "\n" );
636 break;
637 }
638}
639
640
642{
643 // add if minimal here
644 fmt::print( m_file, "{}", "M30\n" );
645 fclose( m_file );
646}
647
648
650{
651 wxFileName fn = m_pcb->GetFileName();
652 wxString extend;
653
654 extend << wxT( "-" )
655 << wxString::FromUTF8( layerPairName( aSpan.Pair() ).c_str() )
656 << wxT( "-backdrill" );
657
658 fn.SetName( fn.GetName() + extend );
659 fn.SetExt( m_drillFileExtension );
660
661 return fn;
662}
663
664
665bool EXCELLON_WRITER::writeBackdrillLayerPairFile( const wxString& aPlotDirectory,
666 REPORTER* aReporter, const DRILL_SPAN& aSpan )
667{
668 wxFileName fn = getBackdrillLayerPairFileName( aSpan );
669 fn.SetPath( aPlotDirectory );
670
671 wxString fullFilename = fn.GetFullPath();
672 FILE* file = wxFopen( fullFilename, wxT( "w" ) );
673
674 if( file == nullptr )
675 {
676 if( aReporter )
677 {
678 wxString msg;
679 msg.Printf( _( "Failed to create file '%s'." ), fullFilename );
680 aReporter->Report( msg, RPT_SEVERITY_ERROR );
681 }
682
683 return false;
684 }
685 else if( aReporter )
686 {
687 wxString msg;
688 msg.Printf( _( "Created file '%s'" ), fullFilename );
689 aReporter->Report( msg, RPT_SEVERITY_ACTION );
690 }
691
692 try
693 {
694 createDrillFile( file, aSpan, TYPE_FILE::NPTH_FILE, true );
695 }
696 catch( ... )
697 {
698 fclose( file );
699
700 if( aReporter )
701 {
702 wxString msg;
703 msg.Printf( _( "Failed to write file '%s'." ), fullFilename );
704 aReporter->Report( msg, RPT_SEVERITY_ERROR );
705 }
706
707 return false;
708 }
709
710 return true;
711}
712
713
714void EXCELLON_WRITER::writeHoleComments( const HOLE_INFO& aHole, bool aTagBackdrillHit )
715{
716 if( aTagBackdrillHit && aHole.m_IsBackdrill )
717 fmt::print( m_file, "{}", "; backdrill\n" );
718
721 wxT( "front" ) );
722
725 wxT( "back" ) );
726}
727
728
730 int aSizeIU, int aDepthIU, int aAngleDeciDegree,
731 const wxString& aSideLabel )
732{
735 {
736 return;
737 }
738
739 wxString comment;
740 comment << wxT( "; Post-machining " ) << aSideLabel << wxT( " " )
741 << ( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK ? wxT( "countersink" )
742 : wxT( "counterbore" ) );
743
744 wxString sizeStr = formatLinearValue( aSizeIU );
745
746 if( !sizeStr.IsEmpty() )
747 comment << wxT( " dia " ) << sizeStr;
748
749 wxString depthStr = formatLinearValue( aDepthIU );
750
751 if( !depthStr.IsEmpty() )
752 comment << wxT( " depth " ) << depthStr;
753
754 if( aMode == PAD_DRILL_POST_MACHINING_MODE::COUNTERSINK && aAngleDeciDegree > 0 )
755 {
756 double angle = aAngleDeciDegree / 10.0;
757 wxString angleStr;
758
759 if( ( aAngleDeciDegree % 10 ) == 0 )
760 angleStr = fmt::format( "{:.0f}deg", angle );
761 else
762 angleStr = fmt::format( "{:.1f}deg", angle );
763
764 comment << wxT( " angle " ) << angleStr;
765 }
766
767 comment << wxT( "\n" );
768 fmt::print( m_file, "{}", TO_UTF8( comment ) );
769}
770
771
772wxString EXCELLON_WRITER::formatLinearValue( int aValueIU ) const
773{
774 if( aValueIU <= 0 )
775 return wxString();
776
777 double converted = aValueIU * m_conversionUnits;
778 wxString value;
779 value = fmt::format( "{:.{}f}", converted, m_mantissaLenght );
780 value << ( m_unitsMetric ? wxT( "mm" ) : wxT( "in" ) );
781
782 return value;
783}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:121
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:986
wxString GetBuildVersion()
Get the full KiCad version string.
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:372
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.
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:71
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Definition reporter.h:100
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:110
#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.
std::pair< PCB_LAYER_ID, PCB_LAYER_ID > DRILL_LAYER_PAIR
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:76
@ 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
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.