KiCad PCB EDA Suite
pcbplot.cpp File Reference
#include <fctsys.h>
#include <class_plotter.h>
#include <confirm.h>
#include <wxPcbStruct.h>
#include <pcbplot.h>
#include <base_units.h>
#include <reporter.h>
#include <class_board.h>
#include <pcbnew.h>
#include <plotcontroller.h>
#include <pcb_plot_params.h>
#include <wx/ffile.h>
#include <dialog_plot.h>
#include <macros.h>
#include <build_version.h>

Go to the source code of this file.

Functions

const wxString GetGerberProtelExtension (LAYER_NUM aLayer)
 Function GetGerberProtelExtension. More...
 
const wxString GetGerberFileFunctionAttribute (const BOARD *aBoard, LAYER_NUM aLayer)
 Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer, as defined in the Gerber file format specification J1 (chapter 5). More...
 
static const wxString GetGerberFilePolarityAttribute (LAYER_NUM aLayer)
 
static wxString & makeStringCompatX1 (wxString &aText, bool aUseX1CompatibilityMode)
 
void BuildGerberX2Header (const BOARD *aBoard, wxArrayString &aHeader)
 
void AddGerberX2Header (PLOTTER *aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode)
 Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and add them the to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId file format attribute is not added. More...
 
void AddGerberX2Attribute (PLOTTER *aPlotter, const BOARD *aBoard, LAYER_NUM aLayer, bool aUseX1CompatibilityMode)
 Calculates some X2 attributes, as defined in the Gerber file format specification and add them to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId TF.FileFunction TF.FilePolarity. More...
 
void BuildPlotFileName (wxFileName *aFilename, const wxString &aOutputDir, const wxString &aSuffix, const wxString &aExtension)
 Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory, add a suffix to the name and sets the specified extension the suffix is usually the layer name replaces not allowed chars in suffix by '_'. More...
 

Function Documentation

void AddGerberX2Attribute ( PLOTTER aPlotter,
const BOARD aBoard,
LAYER_NUM  aLayer,
bool  aUseX1CompatibilityMode 
)

Calculates some X2 attributes, as defined in the Gerber file format specification and add them to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId TF.FileFunction TF.FilePolarity.

Parameters
aPlotter= the current plotter.
aBoard= the board, needed to extract some info
aLayer= the layer number to create the attribute for
aUseX1CompatibilityMode= false to generate X2 attributes, true to use X1 compatibility (X2 attributes added as structured comments, starting by "G04 #@! " followed by the X2 attribute

Definition at line 465 of file pcbplot.cpp.

References AddGerberX2Header(), PLOTTER::AddLineToHeader(), GetGerberFileFunctionAttribute(), GetGerberFilePolarityAttribute(), and makeStringCompatX1().

Referenced by StartPlotBoard().

467 {
468  AddGerberX2Header( aPlotter, aBoard, aUseX1CompatibilityMode );
469 
470  wxString text;
471 
472  // Add the TF.FileFunction
473  text = GetGerberFileFunctionAttribute( aBoard, aLayer );
474  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
475 
476  // Add the TF.FilePolarity (for layers which support that)
477  text = GetGerberFilePolarityAttribute( aLayer );
478 
479  if( !text.IsEmpty() )
480  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
481 }
void AddGerberX2Header(PLOTTER *aPlotter, const BOARD *aBoard, bool aUseX1CompatibilityMode)
Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and ...
Definition: pcbplot.cpp:368
void AddLineToHeader(const wxString &aExtraString)
Function AddLineToHeader Add a line to the list of free lines to print at the beginning of the file...
static const wxString GetGerberFilePolarityAttribute(LAYER_NUM aLayer)
Definition: pcbplot.cpp:201
static wxString & makeStringCompatX1(wxString &aText, bool aUseX1CompatibilityMode)
Definition: pcbplot.cpp:260
const wxString GetGerberFileFunctionAttribute(const BOARD *aBoard, LAYER_NUM aLayer)
Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer...
Definition: pcbplot.cpp:88
void AddGerberX2Header ( PLOTTER aPlotter,
const BOARD aBoard,
bool  aUseX1CompatibilityMode = false 
)

Calculates some X2 attributes, as defined in the Gerber file format specification J4 (chapter 5) and add them the to the gerber file header: TF.GenerationSoftware TF.CreationDate TF.ProjectId file format attribute is not added.

Parameters
aPlotter= the current plotter.
aBoard= the board, needed to extract some info
aUseX1CompatibilityMode= false to generate X2 attributes, true to use X1 compatibility (X2 attributes added as structured comments, starting by "G04 #@! " followed by the X2 attribute

Definition at line 368 of file pcbplot.cpp.

References PLOTTER::AddLineToHeader(), Format(), BOARD::GetAuxOrigin(), GetBuildVersion(), GetChars(), BOARD::GetFileName(), BOARD::GetPlotOptions(), PCB_PLOT_PARAMS::GetUseAuxOrigin(), makeStringCompatX1(), wxPoint::x, and wxPoint::y.

Referenced by AddGerberX2Attribute(), and GERBER_WRITER::createDrillFile().

370 {
371  wxString text;
372 
373  // Creates the TF,.GenerationSoftware. Format is:
374  // %TF,.GenerationSoftware,<vendor>,<application name>[,<application version>]*%
375  text.Printf( wxT( "%%TF.GenerationSoftware,KiCad,Pcbnew,%s*%%" ), GetBuildVersion() );
376  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
377 
378  // creates the TF.CreationDate ext:
379  // The attribute value must conform to the full version of the ISO 8601
380  // date and time format, including time and time zone. Note that this is
381  // the date the Gerber file was effectively created,
382  // not the time the project of PCB was started
383  wxDateTime date( wxDateTime::GetTimeNow() );
384  // Date format: see http://www.cplusplus.com/reference/ctime/strftime
385  wxString msg = date.Format( wxT( "%z" ) ); // Extract the time zone offset
386  // The time zone offset format is + (or -) mm or hhmm (mm = number of minutes, hh = number of hours)
387  // we want +(or -) hh:mm
388  if( msg.Len() > 3 )
389  msg.insert( 3, ":", 1 ),
390  text.Printf( wxT( "%%TF.CreationDate,%s%s*%%" ), GetChars( date.FormatISOCombined() ), GetChars( msg ) );
391  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
392 
393  // Creates the TF,.ProjectId. Format is (from Gerber file format doc):
394  // %TF.ProjectId,<project id>,<project GUID>,<revision id>*%
395  // <project id> is the name of the project, restricted to basic ASCII symbols only,
396  // and comma not accepted
397  // All illegal chars will be replaced by underscore
398  // <project GUID> is a 32 hexadecimal digits string which is an unique id of a project.
399  // This is a random 128-bit number expressed in 32 hexadecimal digits.
400  // See en.wikipedia.org/wiki/GUID for more information
401  // However Kicad does not handle such a project GUID, so it is built from the board name
402  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
403  wxFileName fn = aBoard->GetFileName();
404  msg = fn.GetFullName();
405  wxString guid;
406 
407  // Build a 32 digits GUID from the board name:
408  for( unsigned ii = 0; ii < msg.Len(); ii++ )
409  {
410  int cc1 = int( msg[ii] ) & 0x0F;
411  int cc2 = ( int( msg[ii] ) >> 4) & 0x0F;
412  guid << wxString::Format( wxT( "%X%X" ), cc2, cc1 );
413 
414  if( guid.Len() >= 32 )
415  break;
416  }
417 
418  // guid has 32 digits, so add missing digits
419  int cnt = 32 - guid.Len();
420 
421  if( cnt > 0 )
422  guid.Append( '0', cnt );
423 
424  // build the <project id> string: this is the board short filename (without ext)
425  // and all non ASCII chars and comma are replaced by '_'
426  msg = fn.GetName();
427  msg.Replace( wxT( "," ), wxT( "_" ) );
428 
429  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
430  wxString rev = ((BOARD*)aBoard)->GetTitleBlock().GetRevision();
431  rev.Replace( wxT( "," ), wxT( "_" ) );
432 
433  if( rev.IsEmpty() )
434  rev = wxT( "rev?" );
435 
436  text.Printf( wxT( "%%TF.ProjectId,%s,%s,%s*%%" ), msg.ToAscii(), GetChars( guid ), rev.ToAscii() );
437  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
438 
439  // Add the TF.SameCoordinates, that specify all gerber files uses the same
440  // origin and orientation, and the registration between files is OK.
441  // The parameter of TF.SameCoordinates is a string that is common
442  // to all files using the same registration and has no special meaning:
443  // this is just a key
444  // Because there is no mirroring/rotation in Kicad, only the plot offset origin
445  // can create incorrect registration.
446  // So we create a key from plot offset options.
447  // and therefore for a given board, all Gerber files having the same key have the same
448  // plot origin and use the same registration
449  //
450  // Currently the key is "Original" when using absolute Pcbnew coordinates,
451  // and te PY ans PY position od auxiliary axis, when using it.
452  // Please, if absolute Pcbnew coordinates, one day, are set by user, change the way
453  // the key is built to ensure file only using the *same* axis have the same key.
454  wxString registration_id = "Original";
455  wxPoint auxOrigin = aBoard->GetAuxOrigin();
456 
457  if( aBoard->GetPlotOptions().GetUseAuxOrigin() && auxOrigin.x && auxOrigin.y )
458  registration_id.Printf( "PX%xPY%x", auxOrigin.x, auxOrigin.y );
459 
460  text.Printf( "%%TF.SameCoordinates,%s*%%", registration_id.GetData() );
461  aPlotter->AddLineToHeader( makeStringCompatX1( text, aUseX1CompatibilityMode ) );
462 }
bool GetUseAuxOrigin() const
void AddLineToHeader(const wxString &aExtraString)
Function AddLineToHeader Add a line to the list of free lines to print at the beginning of the file...
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetFileName() const
Definition: class_board.h:234
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:550
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:343
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
static wxString & makeStringCompatX1(wxString &aText, bool aUseX1CompatibilityMode)
Definition: pcbplot.cpp:260
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void BuildGerberX2Header ( const BOARD aBoard,
wxArrayString &  aHeader 
)

Definition at line 272 of file pcbplot.cpp.

References Format(), BOARD::GetAuxOrigin(), GetBuildVersion(), GetChars(), BOARD::GetFileName(), BOARD::GetPlotOptions(), PCB_PLOT_PARAMS::GetUseAuxOrigin(), wxPoint::x, and wxPoint::y.

Referenced by GERBER_JOBFILE_WRITER::CreateJobFile().

273 {
274  wxString text;
275 
276  // Creates the TF,.GenerationSoftware. Format is:
277  // %TF,.GenerationSoftware,<vendor>,<application name>[,<application version>]*%
278  text.Printf( wxT( "%%TF.GenerationSoftware,KiCad,Pcbnew,%s*%%" ), GetBuildVersion() );
279  aHeader.Add( text );
280 
281  // creates the TF.CreationDate ext:
282  // The attribute value must conform to the full version of the ISO 8601
283  // date and time format, including time and time zone. Note that this is
284  // the date the Gerber file was effectively created,
285  // not the time the project of PCB was started
286  wxDateTime date( wxDateTime::GetTimeNow() );
287  // Date format: see http://www.cplusplus.com/reference/ctime/strftime
288  wxString msg = date.Format( wxT( "%z" ) ); // Extract the time zone offset
289  // The time zone offset format is + (or -) mm or hhmm (mm = number of minutes, hh = number of hours)
290  // we want +(or -) hh:mm
291  if( msg.Len() > 3 )
292  msg.insert( 3, ":", 1 ),
293  text.Printf( wxT( "%%TF.CreationDate,%s%s*%%" ), GetChars( date.FormatISOCombined() ), GetChars( msg ) );
294  aHeader.Add( text );
295 
296  // Creates the TF,.ProjectId. Format is (from Gerber file format doc):
297  // %TF.ProjectId,<project id>,<project GUID>,<revision id>*%
298  // <project id> is the name of the project, restricted to basic ASCII symbols only,
299  // and comma not accepted
300  // All illegal chars will be replaced by underscore
301  // <project GUID> is a 32 hexadecimal digits string which is an unique id of a project.
302  // This is a random 128-bit number expressed in 32 hexadecimal digits.
303  // See en.wikipedia.org/wiki/GUID for more information
304  // However Kicad does not handle such a project GUID, so it is built from the board name
305  // Rem: <project id> accepts only ASCII 7 code (only basic ASCII codes are allowed in gerber files).
306  wxFileName fn = aBoard->GetFileName();
307  msg = fn.GetFullName();
308  wxString guid;
309 
310  // Build a 32 digits GUID from the board name:
311  for( unsigned ii = 0; ii < msg.Len(); ii++ )
312  {
313  int cc1 = int( msg[ii] ) & 0x0F;
314  int cc2 = ( int( msg[ii] ) >> 4) & 0x0F;
315  guid << wxString::Format( wxT( "%X%X" ), cc2, cc1 );
316 
317  if( guid.Len() >= 32 )
318  break;
319  }
320 
321  // guid has 32 digits, so add missing digits
322  int cnt = 32 - guid.Len();
323 
324  if( cnt > 0 )
325  guid.Append( '0', cnt );
326 
327  // build the <project id> string: this is the board short filename (without ext)
328  // and all non ASCII chars and comma are replaced by '_'
329  msg = fn.GetName();
330  msg.Replace( wxT( "," ), wxT( "_" ) );
331 
332  // build the <rec> string. All non ASCII chars and comma are replaced by '_'
333  wxString rev = ((BOARD*)aBoard)->GetTitleBlock().GetRevision();
334  rev.Replace( wxT( "," ), wxT( "_" ) );
335 
336  if( rev.IsEmpty() )
337  rev = wxT( "rev?" );
338 
339  text.Printf( wxT( "%%TF.ProjectId,%s,%s,%s*%%" ), msg.ToAscii(), GetChars( guid ), rev.ToAscii() );
340  aHeader.Add( text );
341 
342  // Add the TF.SameCoordinates, that specify all gerber files uses the same
343  // origin and orientation, and the registration between files is OK.
344  // The parameter of TF.SameCoordinates is a string that is common
345  // to all files using the same registration and has no special meaning:
346  // this is just a key
347  // Because there is no mirroring/rotation in Kicad, only the plot offset origin
348  // can create incorrect registration.
349  // So we create a key from plot offset options.
350  // and therefore for a given board, all Gerber files having the same key have the same
351  // plot origin and use the same registration
352  //
353  // Currently the key is "Original" when using absolute Pcbnew coordinates,
354  // and te PY ans PY position od auxiliary axis, when using it.
355  // Please, if absolute Pcbnew coordinates, one day, are set by user, change the way
356  // the key is built to ensure file only using the *same* axis have the same key.
357  wxString registration_id = "Original";
358  wxPoint auxOrigin = aBoard->GetAuxOrigin();
359 
360  if( aBoard->GetPlotOptions().GetUseAuxOrigin() && auxOrigin.x && auxOrigin.y )
361  registration_id.Printf( "PX%xPY%x", auxOrigin.x, auxOrigin.y );
362 
363  text.Printf( "%%TF.SameCoordinates,%s*%%", registration_id.GetData() );
364  aHeader.Add( text );
365 }
bool GetUseAuxOrigin() const
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetFileName() const
Definition: class_board.h:234
const PCB_PLOT_PARAMS & GetPlotOptions() const
Definition: class_board.h:550
const wxPoint & GetAuxOrigin() const
Definition: class_board.h:343
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
void BuildPlotFileName ( wxFileName *  aFilename,
const wxString &  aOutputDir,
const wxString &  aSuffix,
const wxString &  aExtension 
)

Function BuildPlotFileName (helper function) Complete a plot filename: forces the output directory, add a suffix to the name and sets the specified extension the suffix is usually the layer name replaces not allowed chars in suffix by '_'.

Parameters
aFilename= the wxFileName to initialize Contains the base filename
aOutputDir= the path
aSuffix= the suffix to add to the base filename
aExtension= the file extension

Definition at line 484 of file pcbplot.cpp.

Referenced by DIALOG_SVG_PRINT::ExportSVGFile(), PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

486 {
487  // aFilename contains the base filename only (without path and extension)
488  // when calling this function.
489  // It is expected to be a valid filename (this is usually the board filename)
490  aFilename->SetPath( aOutputDir );
491 
492  // Set the file extension
493  aFilename->SetExt( aExtension );
494 
495  // remove leading and trailing spaces if any from the suffix, if
496  // something survives add it to the name;
497  // also the suffix can contain some not allowed chars in filename (/ \ . :),
498  // so change them to underscore
499  // Remember it can be called from a python script, so the illegal chars
500  // have to be filtered here.
501  wxString suffix = aSuffix;
502  suffix.Trim( true );
503  suffix.Trim( false );
504 
505  wxString badchars = wxFileName::GetForbiddenChars(wxPATH_DOS);
506  badchars.Append( '%' );
507 
508  for( unsigned ii = 0; ii < badchars.Len(); ii++ )
509  suffix.Replace( badchars[ii], wxT("_") );
510 
511  if( !suffix.IsEmpty() )
512  aFilename->SetName( aFilename->GetName() + wxT( "-" ) + suffix );
513 }
const wxString GetGerberFileFunctionAttribute ( const BOARD aBoard,
LAYER_NUM  aLayer 
)

Function GetGerberFileFunctionAttribute Returns the "file function" attribute for aLayer, as defined in the Gerber file format specification J1 (chapter 5).

The returned string includes the "%TF.FileFunction" attribute prefix and the "*%" suffix.

Parameters
aBoard= the board, needed to get the total count of copper layers
aLayer= the layer number to create the attribute for
Returns
The attribute, as a text string

Definition at line 88 of file pcbplot.cpp.

References B_Adhes, B_Cu, B_Fab, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Cu, F_Fab, F_Mask, F_Paste, F_SilkS, GetChars(), BOARD::GetCopperLayerCount(), BOARD::GetLayerType(), IsCopperLayer(), LT_MIXED, LT_POWER, LT_SIGNAL, and ToLAYER_ID().

Referenced by AddGerberX2Attribute().

89 {
90  wxString attrib;
91 
92  switch( aLayer )
93  {
94  case F_Adhes:
95  attrib = "Glue,Top";
96  break;
97 
98  case B_Adhes:
99  attrib = "Glue,Bot";
100  break;
101 
102  case F_SilkS:
103  attrib = "Legend,Top";
104  break;
105 
106  case B_SilkS:
107  attrib = "Legend,Bot";
108  break;
109 
110  case F_Mask:
111  attrib = "Soldermask,Top";
112  break;
113 
114  case B_Mask:
115  attrib = "Soldermask,Bot";
116  break;
117 
118  case F_Paste:
119  attrib = "Paste,Top";
120  break;
121 
122  case B_Paste:
123  attrib = "Paste,Bot";
124  break;
125 
126  case Edge_Cuts:
127  // Board outline.
128  // Can be "Profile,NP" (Not Plated: usual) or "Profile,P"
129  // This last is the exception (Plated)
130  attrib = "Profile,NP";
131  break;
132 
133  case Dwgs_User:
134  attrib = "Drawing";
135  break;
136 
137  case Cmts_User:
138  attrib = "Other,Comment";
139  break;
140 
141  case Eco1_User:
142  attrib = "Other,ECO1";
143  break;
144 
145  case Eco2_User:
146  attrib = "Other,ECO2";
147  break;
148 
149  case B_Fab:
150  attrib = "Other,Fab,Bot";
151  break;
152 
153  case F_Fab:
154  attrib = "Other,Fab,Top";
155  break;
156 
157  case B_Cu:
158  attrib.Printf( wxT( "Copper,L%d,Bot" ), aBoard->GetCopperLayerCount() );
159  break;
160 
161  case F_Cu:
162  attrib = "Copper,L1,Top";
163  break;
164 
165  default:
166  if( IsCopperLayer( aLayer ) )
167  attrib.Printf( wxT( "Copper,L%d,Inr" ), aLayer+1 );
168  else
169  attrib.Printf( wxT( "Other,User" ), aLayer+1 );
170  break;
171  }
172 
173  // Add the signal type of the layer, if relevant
174  if( IsCopperLayer( aLayer ) )
175  {
176  LAYER_T type = aBoard->GetLayerType( ToLAYER_ID( aLayer ) );
177 
178  switch( type )
179  {
180  case LT_SIGNAL:
181  attrib += ",Signal";
182  break;
183  case LT_POWER:
184  attrib += ",Plane";
185  break;
186  case LT_MIXED:
187  attrib += ",Mixed";
188  break;
189  default:
190  break; // do nothing (but avoid a warning for unhandled LAYER_T values from GCC)
191  }
192  }
193 
194  wxString fileFct;
195  fileFct.Printf( "%%TF.FileFunction,%s*%%", GetChars( attrib ) );
196 
197  return fileFct;
198 }
int GetCopperLayerCount() const
Function GetCopperLayerCount.
LAYER_T
Enum LAYER_T gives the allowed types of layers, same as Specctra DSN spec.
Definition: class_board.h:71
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
LAYER_T GetLayerType(PCB_LAYER_ID aLayer) const
Function GetLayerType returns the type of the copper layer given by aLayer.
PCB_LAYER_ID ToLAYER_ID(int aLayer)
Definition: lset.cpp:774
static const wxString GetGerberFilePolarityAttribute ( LAYER_NUM  aLayer)
static

Definition at line 201 of file pcbplot.cpp.

References B_Adhes, B_Mask, B_Paste, B_SilkS, F_Adhes, F_Mask, F_Paste, F_SilkS, and IsCopperLayer().

Referenced by AddGerberX2Attribute().

202 {
203  /* build the string %TF.FilePolarity,Positive*%
204  * or %TF.FilePolarity,Negative*%
205  * an emply string for layers which do not use a polarity
206  *
207  * The value of the .FilePolarity specifies whether the image represents the
208  * presence or absence of material.
209  * This attribute can only be used when the file represents a pattern in a material layer,
210  * e.g. copper, solder mask, legend.
211  * Together with.FileFunction it defines the role of that image in
212  * the layer structure of the PCB.
213  * Note that the .FilePolarity attribute does not change the image -
214  * no attribute does.
215  * It changes the interpretation of the image.
216  * For example, in a copper layer in positive polarity a round flash generates a copper pad.
217  * In a copper layer in negative polarity it generates a clearance.
218  * Solder mask images usually represent solder mask openings and are then negative.
219  * This may be counter-intuitive.
220  */
221  int polarity = 0;
222 
223  switch( aLayer )
224  {
225  case F_Adhes:
226  case B_Adhes:
227  case F_SilkS:
228  case B_SilkS:
229  case F_Paste:
230  case B_Paste:
231  polarity = 1;
232  break;
233 
234  case F_Mask:
235  case B_Mask:
236  polarity = -1;
237  break;
238 
239  default:
240  if( IsCopperLayer( aLayer ) )
241  polarity = 1;
242  break;
243  }
244 
245  wxString filePolarity;
246 
247  if( polarity == 1 )
248  filePolarity = "%TF.FilePolarity,Positive*%";
249  if( polarity == -1 )
250  filePolarity = "%TF.FilePolarity,Negative*%";
251 
252  return filePolarity;
253 }
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
const wxString GetGerberProtelExtension ( LAYER_NUM  aLayer)

Function GetGerberProtelExtension.

Returns
the appropriate Gerber file extension for aLayer used by Protel, and still sometimes in use (although the official Gerber Ext is now .gbr)

Definition at line 47 of file pcbplot.cpp.

References B_Adhes, B_Cu, B_Mask, B_Paste, B_SilkS, Cmts_User, Dwgs_User, Eco1_User, Eco2_User, Edge_Cuts, F_Adhes, F_Cu, F_Mask, F_Paste, F_SilkS, Format(), and IsCopperLayer().

Referenced by PLOT_CONTROLLER::OpenPlotfile(), and DIALOG_PLOT::Plot().

48 {
49  if( IsCopperLayer( aLayer ) )
50  {
51  if( aLayer == F_Cu )
52  return wxT( "gtl" );
53  else if( aLayer == B_Cu )
54  return wxT( "gbl" );
55  else
56  {
57  return wxString::Format( wxT( "g%d" ), aLayer+1 );
58  }
59  }
60  else
61  {
62  switch( aLayer )
63  {
64  case B_Adhes: return wxT( "gba" );
65  case F_Adhes: return wxT( "gta" );
66 
67  case B_Paste: return wxT( "gbp" );
68  case F_Paste: return wxT( "gtp" );
69 
70  case B_SilkS: return wxT( "gbo" );
71  case F_SilkS: return wxT( "gto" );
72 
73  case B_Mask: return wxT( "gbs" );
74  case F_Mask: return wxT( "gts" );
75 
76  case Edge_Cuts: return wxT( "gm1" );
77 
78  case Dwgs_User:
79  case Cmts_User:
80  case Eco1_User:
81  case Eco2_User:
82  default: return wxT( "gbr" );
83  }
84  }
85 }
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
bool IsCopperLayer(LAYER_NUM aLayerId)
Function IsCopperLayer tests whether a layer is a copper layer.
static wxString& makeStringCompatX1 ( wxString &  aText,
bool  aUseX1CompatibilityMode 
)
static

Definition at line 260 of file pcbplot.cpp.

Referenced by AddGerberX2Attribute(), and AddGerberX2Header().

261 {
262  if( aUseX1CompatibilityMode )
263  {
264  aText.Replace( "%", "" );
265  aText.Prepend( "G04 #@! " );
266  }
267 
268  return aText;
269 }