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(),
71 msg.Printf( wxS(
"%s%s" ), date.FormatISOCombined(), timezone_offset );
75 msg.Printf( wxS(
"; #@! TF.CreationDate,%s%s" ), date.FormatISOCombined(),
106 wxString bname = aText;
107 int cnt = 16 - bname.Len();
110 bname.Append(
'X', cnt );
115 for(
unsigned ii = 0; ii < 4; ii++ )
117 int cc = int( bname[chr_idx++] ) & 0xFF;
118 guid << wxString::Format(
"%2.2x", cc );
124 for(
unsigned ii = 0; ii < 2; ii++ )
126 int cc = int( bname[chr_idx++] ) & 0xFF;
127 guid << wxString::Format(
"%2.2x", cc );
133 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
134 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
135 guid << wxString::Format(
"%3.3x", cc );
141 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
142 cc += int( bname[chr_idx++] ) & 0xFF;
143 guid << wxString::Format(
"%3.3x", cc );
149 for(
unsigned ii = 0; ii < 6; ii++ )
151 int cc = int( bname[chr_idx++] ) & 0xFF;
152 guid << wxString::Format(
"%2.2x", cc );
160 bool aUseX1StructuredComment,
161 const std::string& aCustomAttribute )
163 std::string attribute_string;
164 std::string comment_string;
177 attribute_string =
"TA.AperFunction,EtchedComponent";
181 attribute_string =
"TA.AperFunction,Conductor";
185 attribute_string =
"TA.AperFunction,Profile";
189 attribute_string =
"TA.AperFunction,ViaPad";
194 attribute_string =
"TA.AperFunction,NonConductor";
199 attribute_string =
"TA.AperFunction,ComponentPad";
205 attribute_string =
"TA.AperFunction,SMDPad,SMDef";
210 attribute_string =
"TA.AperFunction,SMDPad,CuDef";
215 attribute_string =
"TA.AperFunction,BGAPad,SMDef";
220 attribute_string =
"TA.AperFunction,BGAPad,CuDef";
225 attribute_string =
"TA.AperFunction,ConnectorPad";
230 attribute_string =
"TA.AperFunction,WasherPad";
235 attribute_string =
"TA.AperFunction,HeatsinkPad";
240 attribute_string =
"TA.AperFunction,TestPad";
245 attribute_string =
"TA.AperFunction,FiducialPad,Global";
250 attribute_string =
"TA.AperFunction,FiducialPad,Local";
255 attribute_string =
"TA.AperFunction,CastellatedPad";
260 attribute_string =
"TA.AperFunction,CastellatedDrill";
264 attribute_string =
"TA.AperFunction,ViaDrill";
268 attribute_string =
"TA.AperFunction,BackDrill";
273 attribute_string =
"TA.AperFunction,ComponentDrill";
278 attribute_string =
"TA.AperFunction,ComponentDrill,PressFit";
285 comment_string =
"aperture for slot hole";
286 attribute_string =
"TA.AperFunction,ComponentDrill";
292 attribute_string =
"TA.AperFunction,ComponentMain";
299 attribute_string =
"TA.AperFunction,ComponentPin";
307 attribute_string =
"TA.AperFunction,ComponentPin";
313 attribute_string =
"TA.AperFunction,ComponentOutline,Body";
319 attribute_string =
"TA.AperFunction,ComponentOutline,Lead2Lead";
325 attribute_string =
"TA.AperFunction,ComponentOutline,Footprint";
331 attribute_string =
"TA.AperFunction,ComponentOutline,Courtyard";
335 attribute_string =
"TA.AperFunction,Other," + aCustomAttribute;
339 std::string full_attribute_string;
342 if( !attribute_string.empty() )
344 if( !comment_string.empty() )
346 full_attribute_string =
"G04 " + comment_string +
"*\n";
349 if( aUseX1StructuredComment )
351 full_attribute_string +=
"G04 #@! ";
356 full_attribute_string +=
"%";
361 full_attribute_string += attribute_string + eol_string;
363 return full_attribute_string;
371 if( aCode >=
'0' && aCode <=
'9' )
374 if( aCode >=
'A' && aCode <=
'F' )
375 return aCode -
'A' + 10;
377 if( aCode >=
'a' && aCode <=
'f' )
378 return aCode -
'a' + 10;
393 unsigned count = aString.Length();
395 for(
unsigned ii = 0; ii < count; ++ii )
397 unsigned code = aString[ii];
399 if( code ==
'\\' && ii < count-5 && aString[ii+1] ==
'u' )
411 for(
int jj = 0; jj < 4; jj++ )
414 code = aString[ii+jj+2];
430 txt.Append( wxChar( value ) );
436 txt.Append( aString[ii] );
442 txt.Append( aString[ii] );
464 for(
unsigned ii = 0; ii < aString.Length(); ++ii )
466 wxChar code = aString[ii];
487 if( !aAllowUtf8Chars && code > 0x7F )
496 std::snprintf( hexa,
sizeof( hexa ),
"\\u%4.4X", code & 0xFFFF );
521 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
538 if( !aString.IsEmpty() && ( aString[0] !=
'\"' || aString[aString.Len()-1] !=
'\"' ) )
545 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
553#define NO_NET_NAME wxT( "N/C" )
554#define NO_PAD_NAME wxT( "" )
559 bool aUseX1StructuredComment )
561 aClearPreviousAttributes =
false;
562 wxString prepend_string;
565 if( aUseX1StructuredComment )
567 prepend_string =
"G04 #@! ";
572 prepend_string =
"%";
579 if( aData ==
nullptr )
582 std::string pad_attribute_string;
583 std::string net_attribute_string;
584 std::string cmp_attribute_string;
594 pad_attribute_string = prepend_string +
"TO.P,";
610 pad_attribute_string +=
',';
615 pad_attribute_string += eol_string;
622 net_attribute_string = prepend_string +
"TO.N,";
644 net_attribute_string += eol_string;
654 cmp_attribute_string = prepend_string +
"TO.C,";
659 std::string full_attribute_string = pad_attribute_string + net_attribute_string
660 + cmp_attribute_string;
663 std::string short_attribute_string;
667 if( aLastNetAttributes != full_attribute_string )
676 bool clearDict =
false;
678 if( aLastNetAttributes.find(
"TO.P," ) != std::string::npos )
680 if( pad_attribute_string.empty() )
683 short_attribute_string.insert( 0, prepend_string +
"TO.P" + eol_string );
687 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
690 short_attribute_string += pad_attribute_string;
695 short_attribute_string += pad_attribute_string;
698 if( aLastNetAttributes.find(
"TO.N," ) != std::string::npos )
700 if( net_attribute_string.empty() )
703 short_attribute_string.insert( 0, prepend_string +
"TO.N" + eol_string );
707 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
710 short_attribute_string += net_attribute_string;
715 short_attribute_string += net_attribute_string;
718 if( aLastNetAttributes.find(
"TO.C," ) != std::string::npos )
720 if( cmp_attribute_string.empty() )
728 if( pad_attribute_string.empty() )
729 short_attribute_string.insert( 0, prepend_string +
"TO.C" + eol_string );
736 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
739 short_attribute_string += cmp_attribute_string;
744 short_attribute_string += cmp_attribute_string;
747 aClearPreviousAttributes = clearDict;
749 aLastNetAttributes = full_attribute_string;
752 aPrintedText = full_attribute_string;
754 aPrintedText = short_attribute_string;
776 wxString start_of_line(
"%TO." );
777 wxString end_of_line(
"*%\n" );
779 wxString mountTypeStrings[] =
787 if( !
m_MPN.IsEmpty() )
788 text << start_of_line <<
"CMPN," <<
m_MPN << end_of_line;
791 text << start_of_line <<
"Cpkg," <<
m_Package << end_of_line;
797 text << start_of_line <<
"CVal," <<
m_Value << end_of_line;
805 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