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