31#include <wx/datetime.h>
44 wxDateTime date( wxDateTime::GetTimeNow() );
47 wxString timezone_offset;
48 timezone_offset = date.Format(
"%z" );
53 if( timezone_offset.Len() > 3 )
55 timezone_offset.insert( 3,
":", 1 );
62 msg.Printf( wxS(
"%%TF.CreationDate,%s%s*%%" ), date.FormatISOCombined(), timezone_offset );
66 msg.Printf( wxS(
"G04 #@! TF.CreationDate,%s%s*" ), date.FormatISOCombined(), timezone_offset );
70 msg.Printf( wxS(
"%s%s" ), date.FormatISOCombined(), timezone_offset );
74 msg.Printf( wxS(
"; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(), timezone_offset );
103 wxString bname = aText;
104 int cnt = 16 - bname.Len();
107 bname.Append(
'X', cnt );
112 for(
unsigned ii = 0; ii < 4; ii++ )
114 int cc = int( bname[chr_idx++] ) & 0xFF;
115 guid << wxString::Format(
"%2.2x", cc );
121 for(
unsigned ii = 0; ii < 2; ii++ )
123 int cc = int( bname[chr_idx++] ) & 0xFF;
124 guid << wxString::Format(
"%2.2x", cc );
130 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
131 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
132 guid << wxString::Format(
"%3.3x", cc );
138 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
139 cc += int( bname[chr_idx++] ) & 0xFF;
140 guid << wxString::Format(
"%3.3x", cc );
146 for(
unsigned ii = 0; ii < 6; ii++ )
148 int cc = int( bname[chr_idx++] ) & 0xFF;
149 guid << wxString::Format(
"%2.2x", cc );
157 bool aUseX1StructuredComment )
159 std::string attribute_string;
160 std::string comment_string;
173 attribute_string =
"TA.AperFunction,EtchedComponent";
177 attribute_string =
"TA.AperFunction,Conductor";
181 attribute_string =
"TA.AperFunction,Profile";
185 attribute_string =
"TA.AperFunction,ViaPad";
190 attribute_string =
"TA.AperFunction,NonConductor";
195 attribute_string =
"TA.AperFunction,ComponentPad";
201 attribute_string =
"TA.AperFunction,SMDPad,SMDef";
206 attribute_string =
"TA.AperFunction,SMDPad,CuDef";
211 attribute_string =
"TA.AperFunction,BGAPad,SMDef";
216 attribute_string =
"TA.AperFunction,BGAPad,CuDef";
221 attribute_string =
"TA.AperFunction,ConnectorPad";
226 attribute_string =
"TA.AperFunction,WasherPad";
231 attribute_string =
"TA.AperFunction,HeatsinkPad";
236 attribute_string =
"TA.AperFunction,TestPad";
241 attribute_string =
"TA.AperFunction,FiducialPad,Global";
246 attribute_string =
"TA.AperFunction,FiducialPad,Local";
251 attribute_string =
"TA.AperFunction,CastellatedPad";
256 attribute_string =
"TA.AperFunction,CastellatedDrill";
260 attribute_string =
"TA.AperFunction,ViaDrill";
265 attribute_string =
"TA.AperFunction,ComponentDrill";
272 comment_string =
"aperture for slot hole";
273 attribute_string =
"TA.AperFunction,ComponentDrill";
279 attribute_string =
"TA.AperFunction,ComponentMain";
286 attribute_string =
"TA.AperFunction,ComponentPin";
294 attribute_string =
"TA.AperFunction,ComponentPin";
300 attribute_string =
"TA.AperFunction,ComponentOutline,Body";
306 attribute_string =
"TA.AperFunction,ComponentOutline,Lead2Lead";
312 attribute_string =
"TA.AperFunction,ComponentOutline,Footprint";
318 attribute_string =
"TA.AperFunction,ComponentOutline,Courtyard";
324 std::string full_attribute_string;
327 if( !attribute_string.empty() )
329 if( !comment_string.empty() )
331 full_attribute_string =
"G04 " + comment_string +
"*\n";
334 if( aUseX1StructuredComment )
336 full_attribute_string +=
"G04 #@! ";
341 full_attribute_string +=
"%";
346 full_attribute_string += attribute_string + eol_string;
348 return full_attribute_string;
356 if( aCode >=
'0' && aCode <=
'9' )
359 if( aCode >=
'A' && aCode <=
'F' )
360 return aCode -
'A' + 10;
362 if( aCode >=
'a' && aCode <=
'f' )
363 return aCode -
'a' + 10;
378 unsigned count = aString.Length();
380 for(
unsigned ii = 0; ii < count; ++ii )
382 unsigned code = aString[ii];
384 if( code ==
'\\' && ii < count-5 && aString[ii+1] ==
'u' )
396 for(
int jj = 0; jj < 4; jj++ )
399 code = aString[ii+jj+2];
415 txt.Append( wxChar( value ) );
421 txt.Append( aString[ii] );
427 txt.Append( aString[ii] );
449 for(
unsigned ii = 0; ii < aString.Length(); ++ii )
451 wxChar code = aString[ii];
472 if( !aAllowUtf8Chars && code > 0x7F )
481 std::snprintf( hexa,
sizeof( hexa ),
"\\u%4.4X", code & 0xFFFF );
506 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
523 if( !aString.IsEmpty() && ( aString[0] !=
'\"' || aString[aString.Len()-1] !=
'\"' ) )
530 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
538#define NO_NET_NAME wxT( "N/C" )
539#define NO_PAD_NAME wxT( "" )
544 bool aUseX1StructuredComment )
546 aClearPreviousAttributes =
false;
547 wxString prepend_string;
550 if( aUseX1StructuredComment )
552 prepend_string =
"G04 #@! ";
557 prepend_string =
"%";
564 if( aData ==
nullptr )
567 std::string pad_attribute_string;
568 std::string net_attribute_string;
569 std::string cmp_attribute_string;
579 pad_attribute_string = prepend_string +
"TO.P,";
595 pad_attribute_string +=
',';
600 pad_attribute_string += eol_string;
607 net_attribute_string = prepend_string +
"TO.N,";
629 net_attribute_string += eol_string;
639 cmp_attribute_string = prepend_string +
"TO.C,";
644 std::string full_attribute_string = pad_attribute_string + net_attribute_string
645 + cmp_attribute_string;
648 std::string short_attribute_string;
652 if( aLastNetAttributes != full_attribute_string )
661 bool clearDict =
false;
663 if( aLastNetAttributes.find(
"TO.P," ) != std::string::npos )
665 if( pad_attribute_string.empty() )
668 short_attribute_string.insert( 0, prepend_string +
"TO.P" + eol_string );
672 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
675 short_attribute_string += pad_attribute_string;
680 short_attribute_string += pad_attribute_string;
683 if( aLastNetAttributes.find(
"TO.N," ) != std::string::npos )
685 if( net_attribute_string.empty() )
688 short_attribute_string.insert( 0, prepend_string +
"TO.N" + eol_string );
692 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
695 short_attribute_string += net_attribute_string;
700 short_attribute_string += net_attribute_string;
703 if( aLastNetAttributes.find(
"TO.C," ) != std::string::npos )
705 if( cmp_attribute_string.empty() )
713 if( pad_attribute_string.empty() )
714 short_attribute_string.insert( 0, prepend_string +
"TO.C" + eol_string );
721 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
724 short_attribute_string += cmp_attribute_string;
729 short_attribute_string += cmp_attribute_string;
732 aClearPreviousAttributes = clearDict;
734 aLastNetAttributes = full_attribute_string;
737 aPrintedText = full_attribute_string;
739 aPrintedText = short_attribute_string;
766 wxString start_of_line(
"%TO." );
767 wxString end_of_line(
"*%\n" );
769 wxString mountTypeStrings[] =
777 if( !
m_MPN.IsEmpty() )
778 text << start_of_line <<
"CMPN," <<
m_MPN << end_of_line;
781 text << start_of_line <<
"Cpkg," <<
m_Package << end_of_line;
787 text << start_of_line <<
"CVal," <<
m_Value << end_of_line;
795 text << start_of_line <<
"CMnt," << mountTypeStrings[
m_MountType] << end_of_line;
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