KiCad PCB EDA Suite
Loading...
Searching...
No Matches
gbr_metadata.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) 2019 Jean-Pierre Charras, jp.charras at wanadoo.fr
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
30#include <wx/string.h>
31#include <wx/datetime.h>
32
33#include <gbr_metadata.h>
34#include <core/utf8.h>
35
36
38{
39 // creates the CreationDate attribute:
40 // The attribute value must conform to the full version of the ISO 8601
41 // date and time format, including time and time zone. Note that this is
42 // the date the Gerber file was effectively created,
43 // not the time the project of PCB was started
44 wxDateTime date( wxDateTime::GetTimeNow() );
45
46 // Date format: see http://www.cplusplus.com/reference/ctime/strftime
47 wxString timezone_offset; // ISO 8601 offset from UTC in timezone
48 timezone_offset = date.Format( "%z" ); // Extract the time zone offset
49
50 // The time zone offset format is +mm or +hhmm (or -mm or -hhmm)
51 // (mm = number of minutes, hh = number of hours. 1h00mn is returned as +0100)
52 // we want +(or -) hh:mm
53 if( timezone_offset.Len() > 3 ) // format +hhmm or -hhmm found
54 // Add separator between hours and minutes
55 timezone_offset.insert( 3, ":", 1 );
56
57 wxString msg;
58
59 switch( aFormat )
60 {
62 msg.Printf( wxS( "%%TF.CreationDate,%s%s*%%" ), date.FormatISOCombined(), timezone_offset );
63 break;
64
66 msg.Printf( wxS( "G04 #@! TF.CreationDate,%s%s*" ), date.FormatISOCombined(),
67 timezone_offset );
68 break;
69
71 msg.Printf( wxS( "%s%s" ), date.FormatISOCombined(), timezone_offset );
72 break;
73
75 msg.Printf( wxS( "; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(),
76 timezone_offset );
77 break;
78 }
79
80 return msg;
81}
82
83
84wxString GbrMakeProjectGUIDfromString( const wxString& aText )
85{
86 /* Gerber GUID format should be RFC4122 Version 1 or 4.
87 * See en.wikipedia.org/wiki/Universally_unique_identifier
88 * The format is:
89 * xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx
90 * with
91 * x = hexDigit lower/upper case
92 * and
93 * M = '1' or '4' (UUID version: 1 (basic) or 4 (random)) (we use 4: UUID random)
94 * and
95 * N = '8' or '9' or 'A|a' or 'B|b' : UUID variant 1: 2 MSB bits have meaning) (we use N = 9)
96 * N = 1000 or 1001 or 1010 or 1011 : 10xx means Variant 1 (Variant2: 110x and 111x are
97 * reserved)
98 */
99
100 wxString guid;
101
102 // Build a 32 digits GUID from the board name:
103 // guid has 32 digits, so add chars in name to be sure we can build a 32 digits guid
104 // (i.e. from a 16 char string name)
105 // In fact only 30 digits are used, and 2 UID id
106 wxString bname = aText;
107 int cnt = 16 - bname.Len();
108
109 if( cnt > 0 )
110 bname.Append( 'X', cnt );
111
112 int chr_idx = 0;
113
114 // Output the 8 first hex digits:
115 for( unsigned ii = 0; ii < 4; ii++ )
116 {
117 int cc = int( bname[chr_idx++] ) & 0xFF;
118 guid << wxString::Format( "%2.2x", cc );
119 }
120
121 // Output the 4 next hex digits:
122 guid << '-';
123
124 for( unsigned ii = 0; ii < 2; ii++ )
125 {
126 int cc = int( bname[chr_idx++] ) & 0xFF;
127 guid << wxString::Format( "%2.2x", cc );
128 }
129
130 // Output the 4 next hex digits (UUID version and 3 digits):
131 guid << "-4"; // first digit: UUID version 4 (M = 4)
132 {
133 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
134 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
135 guid << wxString::Format( "%3.3x", cc );
136 }
137
138 // Output the 4 next hex digits (UUID variant and 3 digits):
139 guid << "-9"; // first digit: UUID variant 1 (N = 9)
140 {
141 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
142 cc += int( bname[chr_idx++] ) & 0xFF;
143 guid << wxString::Format( "%3.3x", cc );
144 }
145
146 // Output the 12 last hex digits:
147 guid << '-';
148
149 for( unsigned ii = 0; ii < 6; ii++ )
150 {
151 int cc = int( bname[chr_idx++] ) & 0xFF;
152 guid << wxString::Format( "%2.2x", cc );
153 }
154
155 return guid;
156}
157
158
160 bool aUseX1StructuredComment,
161 const std::string& aCustomAttribute )
162{
163 std::string attribute_string; // the specific aperture attribute (TA.xxx)
164 std::string comment_string; // a optional G04 comment line to write before the TA. line
165
166 // generate a string to print a Gerber Aperture attribute
167 switch( aAttribute )
168 {
169 // Dummy value (aAttribute must be < GBR_APERTURE_ATTRIB_END).
171 case GBR_APERTURE_ATTRIB_NONE: // idle command: do nothing
172 break;
173
174 case GBR_APERTURE_ATTRIB_ETCHEDCMP: // print info associated to an item
175 // which connects 2 different nets
176 // (Net tees, microwave component)
177 attribute_string = "TA.AperFunction,EtchedComponent";
178 break;
179
180 case GBR_APERTURE_ATTRIB_CONDUCTOR: // print info associated to a track
181 attribute_string = "TA.AperFunction,Conductor";
182 break;
183
184 case GBR_APERTURE_ATTRIB_EDGECUT: // print info associated to a board outline
185 attribute_string = "TA.AperFunction,Profile";
186 break;
187
188 case GBR_APERTURE_ATTRIB_VIAPAD: // print info associated to a flashed via
189 attribute_string = "TA.AperFunction,ViaPad";
190 break;
191
192 case GBR_APERTURE_ATTRIB_NONCONDUCTOR: // print info associated to a item on a copper layer
193 // which is not a track (for instance a text)
194 attribute_string = "TA.AperFunction,NonConductor";
195 break;
196
197 case GBR_APERTURE_ATTRIB_COMPONENTPAD: // print info associated to a flashed
198 // through hole component on outer layer
199 attribute_string = "TA.AperFunction,ComponentPad";
200 break;
201
202 case GBR_APERTURE_ATTRIB_SMDPAD_SMDEF: // print info associated to a flashed for SMD pad.
203 // with solder mask defined from the copper shape
204 // Excluded BGA pads which have their own type
205 attribute_string = "TA.AperFunction,SMDPad,SMDef";
206 break;
207
208 case GBR_APERTURE_ATTRIB_SMDPAD_CUDEF: // print info associated to a flashed SMD pad with
209 // a solder mask defined by the solder mask
210 attribute_string = "TA.AperFunction,SMDPad,CuDef";
211 break;
212
213 case GBR_APERTURE_ATTRIB_BGAPAD_SMDEF: // print info associated to flashed BGA pads with
214 // a solder mask defined by the copper shape
215 attribute_string = "TA.AperFunction,BGAPad,SMDef";
216 break;
217
218 case GBR_APERTURE_ATTRIB_BGAPAD_CUDEF: // print info associated to a flashed BGA pad with
219 // a solder mask defined by the solder mask
220 attribute_string = "TA.AperFunction,BGAPad,CuDef";
221 break;
222
224 // print info associated to a flashed edge connector pad (outer layers)
225 attribute_string = "TA.AperFunction,ConnectorPad";
226 break;
227
229 // print info associated to flashed mechanical pads (NPTH)
230 attribute_string = "TA.AperFunction,WasherPad";
231 break;
232
233 case GBR_APERTURE_ATTRIB_HEATSINKPAD: // print info associated to a flashed heat sink pad
234 // (typically for SMDs)
235 attribute_string = "TA.AperFunction,HeatsinkPad";
236 break;
237
238 case GBR_APERTURE_ATTRIB_TESTPOINT: // print info associated to a flashed test point pad
239 // (typically for SMDs)
240 attribute_string = "TA.AperFunction,TestPad";
241 break;
242
243 case GBR_APERTURE_ATTRIB_FIDUCIAL_GLBL: // print info associated to a flashed fiducial pad
244 // (typically for SMDs)
245 attribute_string = "TA.AperFunction,FiducialPad,Global";
246 break;
247
248 case GBR_APERTURE_ATTRIB_FIDUCIAL_LOCAL: // print info associated to a flashed fiducial pad
249 // (typically for SMDs)
250 attribute_string = "TA.AperFunction,FiducialPad,Local";
251 break;
252
254 // print info associated to a flashed castellated pad (typically for SMDs)
255 attribute_string = "TA.AperFunction,CastellatedPad";
256 break;
257
259 // print info associated to a flashed castellated pad in drill files
260 attribute_string = "TA.AperFunction,CastellatedDrill";
261 break;
262
263 case GBR_APERTURE_ATTRIB_VIADRILL: // print info associated to a via hole in drill files
264 attribute_string = "TA.AperFunction,ViaDrill";
265 break;
266
268 attribute_string = "TA.AperFunction,BackDrill";
269 break;
270
271 case GBR_APERTURE_ATTRIB_CMP_DRILL: // print info associated to a component
272 // round pad hole in drill files
273 attribute_string = "TA.AperFunction,ComponentDrill";
274 break;
275
277 // print info associated to a flashed component pad with pressfit option in drill files
278 attribute_string = "TA.AperFunction,ComponentDrill,PressFit";
279 break;
280
281 // print info associated to a component oblong pad hole in drill files
282 // Same as a round pad hole, but is a specific aperture in drill file and
283 // a G04 comment is added to the aperture function
285 comment_string = "aperture for slot hole";
286 attribute_string = "TA.AperFunction,ComponentDrill";
287 break;
288
289 case GBR_APERTURE_ATTRIB_CMP_POSITION: // print info associated to a component
290 // flashed shape at the component position
291 // in placement files
292 attribute_string = "TA.AperFunction,ComponentMain";
293 break;
294
295 case GBR_APERTURE_ATTRIB_PAD1_POS: // print info associated to a component
296 // flashed shape at pad 1 position
297 // (pad 1 is also pad A1 or pad AA1)
298 // in placement files
299 attribute_string = "TA.AperFunction,ComponentPin";
300 break;
301
302 case GBR_APERTURE_ATTRIB_PADOTHER_POS: // print info associated to a component
303 // flashed shape at pads position (all but pad 1)
304 // in placement files
305 // Currently: (could be changed later) same as
306 // GBR_APERTURE_ATTRIB_PADOTHER_POS
307 attribute_string = "TA.AperFunction,ComponentPin";
308 break;
309
310 case GBR_APERTURE_ATTRIB_CMP_BODY: // print info associated to a component
311 // print the component physical body
312 // polygon in placement files
313 attribute_string = "TA.AperFunction,ComponentOutline,Body";
314 break;
315
316 case GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD: // print info associated to a component
317 // print the component physical lead to lead
318 // polygon in placement files
319 attribute_string = "TA.AperFunction,ComponentOutline,Lead2Lead";
320 break;
321
322 case GBR_APERTURE_ATTRIB_CMP_FOOTPRINT: // print info associated to a component
323 // print the component footprint bounding box
324 // polygon in placement files
325 attribute_string = "TA.AperFunction,ComponentOutline,Footprint";
326 break;
327
328 case GBR_APERTURE_ATTRIB_CMP_COURTYARD: // print info associated to a component
329 // print the component courtyard
330 // polygon in placement files
331 attribute_string = "TA.AperFunction,ComponentOutline,Courtyard";
332 break;
333
335 attribute_string = "TA.AperFunction,Other," + aCustomAttribute;
336 break;
337 }
338
339 std::string full_attribute_string;
340 wxString eol_string;
341
342 if( !attribute_string.empty() )
343 {
344 if( !comment_string.empty() )
345 {
346 full_attribute_string = "G04 " + comment_string + "*\n";
347 }
348
349 if( aUseX1StructuredComment )
350 {
351 full_attribute_string += "G04 #@! ";
352 eol_string = "*\n";
353 }
354 else
355 {
356 full_attribute_string += "%";
357 eol_string = "*%\n";
358 }
359 }
360
361 full_attribute_string += attribute_string + eol_string;
362
363 return full_attribute_string;
364}
365
366
367// Helper function to convert a ascii hex char to its integer value
368// If the char is not a hexa char, return -1
369int char2Hex( unsigned aCode )
370{
371 if( aCode >= '0' && aCode <= '9' )
372 return aCode - '0';
373
374 if( aCode >= 'A' && aCode <= 'F' )
375 return aCode - 'A' + 10;
376
377 if( aCode >= 'a' && aCode <= 'f' )
378 return aCode - 'a' + 10;
379
380 return -1;
381}
382
383
384wxString FormatStringFromGerber( const wxString& aString )
385{
386 // make the inverse conversion of FormatStringToGerber()
387 // It converts a "normalized" gerber string containing escape sequences
388 // and convert it to a 16 bits Unicode char
389 // and return a wxString (Unicode 16) from the gerber string
390 // Note the initial gerber string can already contain Unicode chars.
391 wxString txt; // The string converted from Gerber string
392
393 unsigned count = aString.Length();
394
395 for( unsigned ii = 0; ii < count; ++ii )
396 {
397 unsigned code = aString[ii];
398
399 if( code == '\\' && ii < count-5 && aString[ii+1] == 'u' )
400 {
401 // Note the latest Gerber X2 spec (2019 06) uses \uXXXX to encode
402 // the Unicode XXXX hexadecimal value
403 // If 4 chars next to 'u' are hexadecimal chars,
404 // Convert these 4 hexadecimal digits to a 16 bit Unicode
405 // (Gerber allows only 4 hexadecimal digits)
406 // If an error occurs, the escape sequence is not translated,
407 // and used "as this"
408 long value = 0;
409 bool error = false;
410
411 for( int jj = 0; jj < 4; jj++ )
412 {
413 value <<= 4;
414 code = aString[ii+jj+2];
415
416 int hexa = char2Hex( code );
417
418 if( hexa >= 0 )
419 value += hexa;
420 else
421 {
422 error = true;
423 break;
424 }
425 }
426
427 if( !error )
428 {
429 if( value >= ' ' ) // Is a valid wxChar ?
430 txt.Append( wxChar( value ) );
431
432 ii += 5;
433 }
434 else
435 {
436 txt.Append( aString[ii] );
437 continue;
438 }
439 }
440 else
441 {
442 txt.Append( aString[ii] );
443 }
444 }
445
446 return txt;
447}
448
449
450wxString ConvertNotAllowedCharsInGerber( const wxString& aString, bool aAllowUtf8Chars,
451 bool aQuoteString )
452{
453 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
454 * 16 bits sequence Unicode
455 * However if aAllowUtf8Chars is true only unauthorized codes will be escaped, because some
456 * Gerber files accept UTF8 chars.
457 * unauthorized codes are ',' '*' '%' '\' '"' and are used as separators in Gerber files
458 */
459 wxString txt;
460
461 if( aQuoteString )
462 txt << "\"";
463
464 for( unsigned ii = 0; ii < aString.Length(); ++ii )
465 {
466 wxChar code = aString[ii];
467 bool convert = false;
468
469 switch( code )
470 {
471 case '\\':
472 case '%':
473 case '*':
474 case ',':
475 convert = true;
476 break;
477
478 case '"':
479 if( aQuoteString )
480 convert = true;
481 break;
482
483 default:
484 break;
485 }
486
487 if( !aAllowUtf8Chars && code > 0x7F )
488 convert = true;
489
490 if( convert )
491 {
492 // Convert code to 4 hexadecimal digit
493 // (Gerber allows only 4 hexadecimal digit) in escape seq:
494 // "\uXXXX", XXXX is the Unicode 16 bits hexa value
495 char hexa[32];
496 std::snprintf( hexa, sizeof( hexa ), "\\u%4.4X", code & 0xFFFF );
497 txt += hexa;
498 }
499 else
500 {
501 txt += code;
502 }
503 }
504
505 if( aQuoteString )
506 txt << "\"";
507
508 return txt;
509}
510
511
513{
514 wxString converted;
515
516 if( !m_field.IsEmpty() )
518
519 // Convert the char string to std::string. Be careful when converting a wxString to
520 // a std::string: using static_cast<const char*> is mandatory
521 std::string txt = static_cast<const char*>( converted.utf8_str() );
522
523 return txt;
524}
525
526
527std::string FormatStringToGerber( const wxString& aString )
528{
529 wxString converted;
530
531 /* format string means convert any code > 0x7E and unauthorized codes to a hexadecimal
532 * 16 bits sequence Unicode
533 * unauthorized codes are ',' '*' '%' '\'
534 * This conversion is not made for quoted strings, because if the string is
535 * quoted, the conversion is expected to be already made, and the returned string must use
536 * UTF8 encoding
537 */
538 if( !aString.IsEmpty() && ( aString[0] != '\"' || aString[aString.Len()-1] != '\"' ) )
539 converted = ConvertNotAllowedCharsInGerber( aString, false, false );
540 else
541 converted = aString;
542
543 // Convert the char string to std::string. Be careful when converting a wxString to
544 // a std::string: using static_cast<const char*> is mandatory
545 std::string txt = static_cast<const char*>( converted.utf8_str() );
546
547 return txt;
548}
549
550
551// Netname and Pan num fields cannot be empty in Gerber files
552// Normalized names must be used, if any
553#define NO_NET_NAME wxT( "N/C" ) // net name of not connected pads (one pad net) (normalized)
554#define NO_PAD_NAME wxT( "" ) // pad name of pads without pad name/number (not normalized)
555
556
557bool FormatNetAttribute( std::string& aPrintedText, std::string& aLastNetAttributes,
558 const GBR_NETLIST_METADATA* aData, bool& aClearPreviousAttributes,
559 bool aUseX1StructuredComment )
560{
561 aClearPreviousAttributes = false;
562 wxString prepend_string;
563 wxString eol_string;
564
565 if( aUseX1StructuredComment )
566 {
567 prepend_string = "G04 #@! ";
568 eol_string = "*\n";
569 }
570 else
571 {
572 prepend_string = "%";
573 eol_string = "*%\n";
574 }
575
576 // print a Gerber net attribute record.
577 // it is added to the object attributes dictionary
578 // On file, only modified or new attributes are printed.
579 if( aData == nullptr )
580 return false;
581
582 std::string pad_attribute_string;
583 std::string net_attribute_string;
584 std::string cmp_attribute_string;
585
587 return false; // idle command: do nothing
588
590 {
591 // print info associated to a flashed pad (cmpref, pad name, and optionally pin function)
592 // example1: %TO.P,R5,3*%
593 // example2: %TO.P,R5,3,reset*%
594 pad_attribute_string = prepend_string + "TO.P,";
595 pad_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + ",";
596
597 if( aData->m_Padname.IsEmpty() )
598 {
599 // Happens for "mechanical" or never connected pads
600 pad_attribute_string += FormatStringToGerber( NO_PAD_NAME );
601 }
602 else
603 {
604 pad_attribute_string += aData->m_Padname.GetGerberString();
605
606 // In Pcbnew, the pin function comes from the schematic.
607 // so it exists only for named pads
608 if( !aData->m_PadPinFunction.IsEmpty() )
609 {
610 pad_attribute_string += ',';
611 pad_attribute_string += aData->m_PadPinFunction.GetGerberString();
612 }
613 }
614
615 pad_attribute_string += eol_string;
616 }
617
619 {
620 // print info associated to a net
621 // example: %TO.N,Clk3*%
622 net_attribute_string = prepend_string + "TO.N,";
623
624 if( aData->m_Netname.IsEmpty() )
625 {
626 if( aData->m_NotInNet )
627 {
628 // Happens for not connectable pads: mechanical pads
629 // and pads with no padname/num
630 // In this case the net name must be left empty
631 }
632 else
633 {
634 // Happens for not connected pads: use a normalized
635 // dummy name
636 net_attribute_string += FormatStringToGerber( NO_NET_NAME );
637 }
638 }
639 else
640 {
641 net_attribute_string += FormatStringToGerber( aData->m_Netname );
642 }
643
644 net_attribute_string += eol_string;
645 }
646
649 {
650 // print info associated to a footprint
651 // example: %TO.C,R2*%
652 // Because GBR_NETINFO_PAD option already contains this info, it is not
653 // created here for a GBR_NETINFO_PAD attribute
654 cmp_attribute_string = prepend_string + "TO.C,";
655 cmp_attribute_string += FormatStringToGerber( aData->m_Cmpref ) + eol_string;
656 }
657
658 // the full list of requested attributes:
659 std::string full_attribute_string = pad_attribute_string + net_attribute_string
660 + cmp_attribute_string;
661 // the short list of requested attributes
662 // (only modified or new attributes are stored here):
663 std::string short_attribute_string;
664
665 // Attributes have changed: update attribute string, and see if the previous attribute
666 // list (dictionary in Gerber language) must be cleared
667 if( aLastNetAttributes != full_attribute_string )
668 {
669 // first, remove no longer existing attributes.
670 // Because in KiCad the full attribute list is evaluated for each object,
671 // the entire dictionary is cleared
672 // If m_TryKeepPreviousAttributes is true, only the no longer existing attribute
673 // is cleared.
674 // Note: to avoid interaction between clear attributes and set attributes
675 // the clear attribute is inserted first.
676 bool clearDict = false;
677
678 if( aLastNetAttributes.find( "TO.P," ) != std::string::npos )
679 {
680 if( pad_attribute_string.empty() ) // No more this attribute
681 {
682 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
683 short_attribute_string.insert( 0, prepend_string + "TO.P" + eol_string );
684 else
685 clearDict = true;
686 }
687 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
688 {
689 // This attribute has changed
690 short_attribute_string += pad_attribute_string;
691 }
692 }
693 else // New attribute
694 {
695 short_attribute_string += pad_attribute_string;
696 }
697
698 if( aLastNetAttributes.find( "TO.N," ) != std::string::npos )
699 {
700 if( net_attribute_string.empty() ) // No more this attribute
701 {
702 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
703 short_attribute_string.insert( 0, prepend_string + "TO.N" + eol_string );
704 else
705 clearDict = true;
706 }
707 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
708 {
709 // This attribute has changed.
710 short_attribute_string += net_attribute_string;
711 }
712 }
713 else // New attribute
714 {
715 short_attribute_string += net_attribute_string;
716 }
717
718 if( aLastNetAttributes.find( "TO.C," ) != std::string::npos )
719 {
720 if( cmp_attribute_string.empty() ) // No more this attribute
721 {
722 if( aData->m_TryKeepPreviousAttributes ) // Clear only this attribute
723 {
724 // Refinement:
725 // the attribute will be cleared only if there is no pad attribute.
726 // If a pad attribute exists, the component name exists so the old
727 // TO.C value will be updated, therefore no need to clear it before updating
728 if( pad_attribute_string.empty() )
729 short_attribute_string.insert( 0, prepend_string + "TO.C" + eol_string );
730 }
731 else
732 {
733 clearDict = true;
734 }
735 }
736 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
737 {
738 // This attribute has changed.
739 short_attribute_string += cmp_attribute_string;
740 }
741 }
742 else // New attribute
743 {
744 short_attribute_string += cmp_attribute_string;
745 }
746
747 aClearPreviousAttributes = clearDict;
748
749 aLastNetAttributes = full_attribute_string;
750
751 if( clearDict )
752 aPrintedText = full_attribute_string;
753 else
754 aPrintedText = short_attribute_string;
755 }
756
757 return true;
758}
759
760
762{
763 // Clear all strings
764 m_Orientation = 0.0;
765 m_Manufacturer.Clear();
766 m_MPN.Clear();
767 m_Package.Clear();
768 m_Value.Clear();
770}
771
772
774{
775 wxString text;
776 wxString start_of_line( "%TO." );
777 wxString end_of_line( "*%\n" );
778
779 wxString mountTypeStrings[] =
780 {
781 "Other", "SMD", "TH"
782 };
783
784 if( !m_Manufacturer.IsEmpty() )
785 text << start_of_line << "CMfr," << m_Manufacturer << end_of_line;
786
787 if( !m_MPN.IsEmpty() )
788 text << start_of_line << "CMPN," << m_MPN << end_of_line;
789
790 if( !m_Package.IsEmpty() )
791 text << start_of_line << "Cpkg," << m_Package << end_of_line;
792
793 if( !m_Footprint.IsEmpty() )
794 text << start_of_line << "CFtp," << m_Footprint << end_of_line;
795
796 if( !m_Value.IsEmpty() )
797 text << start_of_line << "CVal," << m_Value << end_of_line;
798
799 if( !m_LibraryName.IsEmpty() )
800 text << start_of_line << "CLbN," << m_LibraryName << end_of_line;
801
802 if( !m_LibraryDescr.IsEmpty() )
803 text << start_of_line << "CLbD," << m_LibraryDescr << end_of_line;
804
805 text << start_of_line << "CMnt," << mountTypeStrings[m_MountType] << end_of_line;
806 text << start_of_line << "CRot," << m_Orientation << end_of_line;
807
808 return text;
809}
@ GBR_APERTURE_ATTRIB_CONDUCTOR
Aperture used for connected items like tracks (not vias).
@ GBR_APERTURE_ATTRIB_VIAPAD
Aperture used for vias.
@ GBR_APERTURE_ATTRIB_ETCHEDCMP
Aperture used for etched components.
@ GBR_APERTURE_ATTRIB_BGAPAD_CUDEF
Aperture used for BGA pad with a solder mask defined by the solder mask.
@ GBR_APERTURE_ATTRIB_PRESSFITDRILL
Aperture used for pressfit pads in drill files.
@ GBR_APERTURE_ATTRIB_PAD1_POS
Aperture used for flashed pin 1 (or A1 or AA1) position in placement files.
@ GBR_APERTURE_ATTRIB_BACKDRILL
Aperture used for pad holes in drill files.
@ GBR_APERTURE_ATTRIB_HEATSINKPAD
Aperture used for heat sink pad (typically for SMDs).
@ GBR_APERTURE_ATTRIB_CMP_OBLONG_DRILL
Aperture used for pads oblong holes in drill files.
@ GBR_APERTURE_ATTRIB_CMP_COURTYARD
Aperture used to draw component outline courtyard in placement files.
@ GBR_APERTURE_ATTRIB_TESTPOINT
Aperture used for test point pad (outer layers).
@ GBR_APERTURE_ATTRIB_SMDPAD_SMDEF
Aperture used for SMD pad. Excluded BGA pads which have their own type.
@ GBR_APERTURE_ATTRIB_SMDPAD_CUDEF
Aperture used for SMD pad with a solder mask defined by the solder mask.
@ GBR_APERTURE_ATTRIB_NONE
uninitialized attribute.
@ GBR_APERTURE_ATTRIB_CONNECTORPAD
Aperture used for edge connector pad (outer layers).
@ GBR_APERTURE_ATTRIB_CASTELLATEDDRILL
Aperture used for castellated pads in drill files.
@ GBR_APERTURE_ATTRIB_NONCONDUCTOR
Aperture used for not connected items (texts, outlines on copper).
@ GBR_APERTURE_ATTRIB_END
sentinel: max value
@ GBR_APERTURE_ATTRIB_CMP_POSITION
Aperture used for flashed cmp position in placement files.
@ GBR_APERTURE_ATTRIB_CMP_BODY
Aperture used to draw component physical body outline without pins in placement files.
@ GBR_APERTURE_ATTRIB_BGAPAD_SMDEF
Aperture used for BGA pads with a solder mask defined by the copper shape.
@ GBR_APERTURE_ATTRIB_WASHERPAD
Aperture used for mechanical pads (NPTH).
@ GBR_APERTURE_ATTRIB_PADOTHER_POS
Aperture used for flashed pads position in placement files.
@ GBR_APERTURE_ATTRIB_COMPONENTPAD
Aperture used for through hole component on outer layer.
@ GBR_APERTURE_ATTRIB_VIADRILL
Aperture used for backdrill holes in drill files.
@ GBR_APERTURE_ATTRIB_CMP_FOOTPRINT
Aperture used to draw component footprint bounding box in placement files.
@ GBR_APERTURE_ATTRIB_CMP_LEAD2LEAD
Aperture used to draw component physical body outline with pins in placement files.
@ GBR_APERTURE_ATTRIB_FIDUCIAL_GLBL
Aperture used for fiducial pad (outer layers), at board level.
@ GBR_APERTURE_ATTRIB_CASTELLATEDPAD
Aperture used for castellated pads in copper layer files.
@ GBR_APERTURE_ATTRIB_FIDUCIAL_LOCAL
Aperture used for fiducial pad (outer layers), at footprint level.
@ GBR_APERTURE_ATTRIB_EDGECUT
Aperture used for board cutout,.
static std::string FormatAttribute(GBR_APERTURE_ATTRIB aAttribute, bool aUseX1StructuredComment, const std::string &aCustomAttribute)
wxString FormatCmpPnPMetadata()
One line by non empty data the orientation (.CRot) and mount type (.CMnt) are always generated.
std::string GetGerberString() const
wxString m_field
the Unicode text to print in Gbr file (after escape and quoting)
bool m_useUTF8
true to use UTF8, false to escape non ASCII7 chars
bool m_escapeString
true to quote the field in gbr file
Information which can be added in a gerber file as attribute of an object.
int m_NetAttribType
the type of net info (used to define the gerber string to create)
wxString m_Cmpref
the component reference parent of the data
@ GBR_NETINFO_NET
print info associated to a net (TO.N attribute)
@ GBR_NETINFO_UNSPECIFIED
idle command (no command)
@ GBR_NETINFO_CMP
print info associated to a component (TO.C attribute)
@ GBR_NETINFO_PAD
print info associated to a flashed pad (TO.P attribute)
GBR_DATA_FIELD m_PadPinFunction
for a pad: the pin function (defined in schematic)
bool m_TryKeepPreviousAttributes
If true, do not clear all attributes when a attribute has changed.
bool m_NotInNet
true if a pad of a footprint cannot be connected (for instance a mechanical NPTH, ot a not named pad)...
GBR_DATA_FIELD m_Padname
for a flashed pad: the pad name ((TO.P attribute)
wxString m_Netname
for items associated to a net: the netname
wxString GbrMakeProjectGUIDfromString(const wxString &aText)
Build a project GUID using format RFC4122 Version 1 or 4 from the project name, because a KiCad proje...
#define NO_NET_NAME
#define NO_PAD_NAME
wxString GbrMakeCreationDateAttributeString(GBR_NC_STRING_FORMAT aFormat)
std::string FormatStringToGerber(const wxString &aString)
Normalize aString and convert it to a Gerber std::string.
wxString ConvertNotAllowedCharsInGerber(const wxString &aString, bool aAllowUtf8Chars, bool aQuoteString)
Normalize aString and convert it to a Gerber compatible wxString.
wxString FormatStringFromGerber(const wxString &aString)
Convert a gerber string into a 16 bit Unicode string.
int char2Hex(unsigned aCode)
bool FormatNetAttribute(std::string &aPrintedText, std::string &aLastNetAttributes, const GBR_NETLIST_METADATA *aData, bool &aClearPreviousAttributes, bool aUseX1StructuredComment)
Generate the string to set a net attribute for a graphic object to print to a gerber file.
Handle special data (items attributes) during plot.
GBR_NC_STRING_FORMAT
Create a gerber TF.CreationDate attribute.
@ GBR_NC_STRING_FORMAT_X1
@ GBR_NC_STRING_FORMAT_NCDRILL
@ GBR_NC_STRING_FORMAT_X2
@ GBR_NC_STRING_FORMAT_GBRJOB