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 );
104 wxString bname = aText;
105 int cnt = 16 - bname.Len();
108 bname.Append(
'X', cnt );
113 for(
unsigned ii = 0; ii < 4; ii++ )
115 int cc = int( bname[chr_idx++] ) & 0xFF;
116 guid << wxString::Format(
"%2.2x", cc );
122 for(
unsigned ii = 0; ii < 2; ii++ )
124 int cc = int( bname[chr_idx++] ) & 0xFF;
125 guid << wxString::Format(
"%2.2x", cc );
131 int cc = int( bname[chr_idx++] ) << 4 & 0xFF0;
132 cc += int( bname[chr_idx] ) >> 4 & 0x0F;
133 guid << wxString::Format(
"%3.3x", cc );
139 int cc = (int( bname[chr_idx++] ) & 0x0F) << 8;
140 cc += int( bname[chr_idx++] ) & 0xFF;
141 guid << wxString::Format(
"%3.3x", cc );
147 for(
unsigned ii = 0; ii < 6; ii++ )
149 int cc = int( bname[chr_idx++] ) & 0xFF;
150 guid << wxString::Format(
"%2.2x", cc );
158 bool aUseX1StructuredComment,
159 const std::string& aCustomAttribute )
161 std::string attribute_string;
162 std::string comment_string;
175 attribute_string =
"TA.AperFunction,EtchedComponent";
179 attribute_string =
"TA.AperFunction,Conductor";
183 attribute_string =
"TA.AperFunction,Profile";
187 attribute_string =
"TA.AperFunction,ViaPad";
192 attribute_string =
"TA.AperFunction,NonConductor";
197 attribute_string =
"TA.AperFunction,ComponentPad";
203 attribute_string =
"TA.AperFunction,SMDPad,SMDef";
208 attribute_string =
"TA.AperFunction,SMDPad,CuDef";
213 attribute_string =
"TA.AperFunction,BGAPad,SMDef";
218 attribute_string =
"TA.AperFunction,BGAPad,CuDef";
223 attribute_string =
"TA.AperFunction,ConnectorPad";
228 attribute_string =
"TA.AperFunction,WasherPad";
233 attribute_string =
"TA.AperFunction,HeatsinkPad";
238 attribute_string =
"TA.AperFunction,TestPad";
243 attribute_string =
"TA.AperFunction,FiducialPad,Global";
248 attribute_string =
"TA.AperFunction,FiducialPad,Local";
253 attribute_string =
"TA.AperFunction,CastellatedPad";
258 attribute_string =
"TA.AperFunction,CastellatedDrill";
262 attribute_string =
"TA.AperFunction,ViaDrill";
266 attribute_string =
"TA.AperFunction,BackDrill";
271 attribute_string =
"TA.AperFunction,ComponentDrill";
276 attribute_string =
"TA.AperFunction,ComponentDrill,PressFit";
283 comment_string =
"aperture for slot hole";
284 attribute_string =
"TA.AperFunction,ComponentDrill";
290 attribute_string =
"TA.AperFunction,ComponentMain";
297 attribute_string =
"TA.AperFunction,ComponentPin";
305 attribute_string =
"TA.AperFunction,ComponentPin";
311 attribute_string =
"TA.AperFunction,ComponentOutline,Body";
317 attribute_string =
"TA.AperFunction,ComponentOutline,Lead2Lead";
323 attribute_string =
"TA.AperFunction,ComponentOutline,Footprint";
329 attribute_string =
"TA.AperFunction,ComponentOutline,Courtyard";
333 attribute_string =
"TA.AperFunction,Other," + aCustomAttribute;
337 std::string full_attribute_string;
340 if( !attribute_string.empty() )
342 if( !comment_string.empty() )
344 full_attribute_string =
"G04 " + comment_string +
"*\n";
347 if( aUseX1StructuredComment )
349 full_attribute_string +=
"G04 #@! ";
354 full_attribute_string +=
"%";
359 full_attribute_string += attribute_string + eol_string;
361 return full_attribute_string;
369 if( aCode >=
'0' && aCode <=
'9' )
372 if( aCode >=
'A' && aCode <=
'F' )
373 return aCode -
'A' + 10;
375 if( aCode >=
'a' && aCode <=
'f' )
376 return aCode -
'a' + 10;
391 unsigned count = aString.Length();
393 for(
unsigned ii = 0; ii < count; ++ii )
395 unsigned code = aString[ii];
397 if( code ==
'\\' && ii < count-5 && aString[ii+1] ==
'u' )
409 for(
int jj = 0; jj < 4; jj++ )
412 code = aString[ii+jj+2];
428 txt.Append( wxChar( value ) );
434 txt.Append( aString[ii] );
440 txt.Append( aString[ii] );
462 for(
unsigned ii = 0; ii < aString.Length(); ++ii )
464 wxChar code = aString[ii];
485 if( !aAllowUtf8Chars && code > 0x7F )
494 std::snprintf( hexa,
sizeof( hexa ),
"\\u%4.4X", code & 0xFFFF );
519 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
536 if( !aString.IsEmpty() && ( aString[0] !=
'\"' || aString[aString.Len()-1] !=
'\"' ) )
543 std::string txt =
static_cast<const char*
>( converted.utf8_str() );
551#define NO_NET_NAME wxT( "N/C" )
552#define NO_PAD_NAME wxT( "" )
557 bool aUseX1StructuredComment )
559 aClearPreviousAttributes =
false;
560 wxString prepend_string;
563 if( aUseX1StructuredComment )
565 prepend_string =
"G04 #@! ";
570 prepend_string =
"%";
577 if( aData ==
nullptr )
580 std::string pad_attribute_string;
581 std::string net_attribute_string;
582 std::string cmp_attribute_string;
592 pad_attribute_string = prepend_string +
"TO.P,";
608 pad_attribute_string +=
',';
613 pad_attribute_string += eol_string;
620 net_attribute_string = prepend_string +
"TO.N,";
642 net_attribute_string += eol_string;
652 cmp_attribute_string = prepend_string +
"TO.C,";
657 std::string full_attribute_string = pad_attribute_string + net_attribute_string
658 + cmp_attribute_string;
661 std::string short_attribute_string;
665 if( aLastNetAttributes != full_attribute_string )
674 bool clearDict =
false;
676 if( aLastNetAttributes.find(
"TO.P," ) != std::string::npos )
678 if( pad_attribute_string.empty() )
681 short_attribute_string.insert( 0, prepend_string +
"TO.P" + eol_string );
685 else if( aLastNetAttributes.find( pad_attribute_string ) == std::string::npos )
688 short_attribute_string += pad_attribute_string;
693 short_attribute_string += pad_attribute_string;
696 if( aLastNetAttributes.find(
"TO.N," ) != std::string::npos )
698 if( net_attribute_string.empty() )
701 short_attribute_string.insert( 0, prepend_string +
"TO.N" + eol_string );
705 else if( aLastNetAttributes.find( net_attribute_string ) == std::string::npos )
708 short_attribute_string += net_attribute_string;
713 short_attribute_string += net_attribute_string;
716 if( aLastNetAttributes.find(
"TO.C," ) != std::string::npos )
718 if( cmp_attribute_string.empty() )
726 if( pad_attribute_string.empty() )
727 short_attribute_string.insert( 0, prepend_string +
"TO.C" + eol_string );
734 else if( aLastNetAttributes.find( cmp_attribute_string ) == std::string::npos )
737 short_attribute_string += cmp_attribute_string;
742 short_attribute_string += cmp_attribute_string;
745 aClearPreviousAttributes = clearDict;
747 aLastNetAttributes = full_attribute_string;
750 aPrintedText = full_attribute_string;
752 aPrintedText = short_attribute_string;
774 wxString start_of_line(
"%TO." );
775 wxString end_of_line(
"*%\n" );
777 wxString mountTypeStrings[] =
785 if( !
m_MPN.IsEmpty() )
786 text << start_of_line <<
"CMPN," <<
m_MPN << end_of_line;
789 text << start_of_line <<
"Cpkg," <<
m_Package << end_of_line;
795 text << start_of_line <<
"CVal," <<
m_Value << end_of_line;
803 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