KiCad PCB EDA Suite
GERBER_FILE_IMAGE Class Reference

Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO: move them in GERBER_LAYER class. More...

#include <class_gerber_file_image.h>

Inheritance diagram for GERBER_FILE_IMAGE:
EXCELLON_IMAGE

Public Member Functions

 GERBER_FILE_IMAGE (int layer)
 
virtual ~GERBER_FILE_IMAGE ()
 
void Clear_GERBER_FILE_IMAGE ()
 
bool LoadGerberFile (const wxString &aFullFileName)
 Read and load a gerber file. More...
 
const wxArrayString & GetMessages () const
 
int GetDcodesCount ()
 
virtual void ResetDefaultValues ()
 
COLOR4D GetPositiveDrawColor () const
 
GERBER_DRAW_ITEMGetItemsList ()
 Function GetItemsList. More...
 
GERBER_LAYERGetLayerParams ()
 Function GetLayerParams. More...
 
bool HasNegativeItems ()
 Function HasNegativeItems. More...
 
void ClearMessageList ()
 Function ClearMessageList Clear the message list Call it before reading a Gerber file. More...
 
void AddMessageToList (const wxString &aMessage)
 Function AddMessageToList Add a message to the message list. More...
 
void InitToolTable ()
 Function InitToolTable. More...
 
wxPoint ReadXYCoord (char *&Text)
 Function ReadXYCoord Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm) More...
 
wxPoint ReadIJCoord (char *&Text)
 Function ReadIJCoord Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm) These coordinates are relative, so if coordinate is absent, it's value defaults to 0. More...
 
int GCodeNumber (char *&Text)
 
int DCodeNumber (char *&Text)
 
bool Execute_G_Command (char *&text, int G_command)
 
bool Execute_DCODE_Command (char *&text, int D_command)
 
bool ReadRS274XCommand (char *aBuff, char *&text)
 Function ReadRS274XCommand reads a single RS274X command terminated with a %. More...
 
bool ExecuteRS274XCommand (int command, char *aBuff, char *&text)
 Function ExecuteRS274XCommand executes 1 command. More...
 
bool ReadApertureMacro (char *aBuff, char *&text, FILE *gerber_file)
 Function ReadApertureMacro reads in an aperture macro and saves it in m_aperture_macros. More...
 
D_CODEGetDCODE (int aDCODE, bool aCreateIfNoExist=true)
 Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE. More...
 
APERTURE_MACROFindApertureMacro (const APERTURE_MACRO &aLookup)
 Function FindApertureMacro looks up a previously read in aperture macro. More...
 
void StepAndRepeatItem (const GERBER_DRAW_ITEM &aItem)
 Function StepAndRepeatItem Gerber format has a command Step an Repeat This function must be called when reading a gerber file and after creating a new gerber item that must be repeated (i.e when m_XRepeatCount or m_YRepeatCount are > 1) More...
 
void DisplayImageInfo (GERBVIEW_FRAME *aMainFrame)
 Function DisplayImageInfo has knowledge about the frame and how and where to put status information about this object into the frame's message panel. More...
 
void RemoveAttribute (X2_ATTRIBUTE &aAttribute)
 Function RemoveAttribute. More...
 

Public Attributes

DLIST< GERBER_DRAW_ITEMm_Drawings
 
bool m_InUse
 
bool m_IsVisible
 
COLOR4D m_PositiveDrawColor
 
wxString m_FileName
 
wxString m_ImageName
 
bool m_IsX2_file
 
X2_ATTRIBUTE_FILEFUNCTIONm_FileFunction
 
wxString m_MD5_value
 
wxString m_PartString
 
int m_GraphicLayer
 
bool m_ImageNegative
 
bool m_ImageJustifyXCenter
 
bool m_ImageJustifyYCenter
 
wxPoint m_ImageJustifyOffset
 
bool m_GerbMetric
 
bool m_Relative
 
bool m_NoTrailingZeros
 
bool m_DecimalFormat
 
wxPoint m_ImageOffset
 
wxSize m_FmtScale
 
wxSize m_FmtLen
 
int m_ImageRotation
 
double m_LocalRotation
 
wxPoint m_Offset
 
wxRealPoint m_Scale
 
bool m_SwapAxis
 
bool m_MirrorA
 
bool m_MirrorB
 
int m_Iterpolation
 
int m_Current_Tool
 
int m_Last_Pen_Command
 
int m_CommandState
 
wxPoint m_CurrentPos
 
wxPoint m_PreviousPos
 
wxPoint m_IJPos
 
FILE * m_Current_File
 
int m_Selected_Tool
 
bool m_Has_DCode
 
bool m_360Arc_enbl
 
bool m_PolygonFillMode
 
int m_PolygonFillModeState
 
APERTURE_MACRO_SET m_aperture_macros
 a collection of APERTURE_MACROS, sorted by name More...
 
GBR_NETLIST_METADATA m_NetAttributeDict
 
wxString m_AperFunction
 
std::map< wxString, int > m_ComponentsList
 
std::map< wxString, int > m_NetnamesList
 

Private Attributes

D_CODEm_Aperture_List [TOOLS_MAX_COUNT]
 Dcode (Aperture) List for this layer (max 999) More...
 
bool m_Exposure
 whether an aperture macro tool is flashed on or off More...
 
GERBER_LAYER m_GBRLayerParams
 
wxArrayString m_messagesList
 
int m_hasNegativeItems
 

Detailed Description

Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO: move them in GERBER_LAYER class.

Definition at line 98 of file class_gerber_file_image.h.

Constructor & Destructor Documentation

GERBER_FILE_IMAGE::GERBER_FILE_IMAGE ( int  layer)

Definition at line 92 of file class_gerber_file_image.cpp.

References DIM, m_Aperture_List, m_FileFunction, m_GraphicLayer, m_IsVisible, m_PositiveDrawColor, m_Selected_Tool, ResetDefaultValues(), and WHITE.

93 {
94  m_GraphicLayer = aLayer; // Graphic layer Number
95  m_IsVisible = true; // must be drawn
96  m_PositiveDrawColor = WHITE; // The color used to draw positive items for this image
97 
98  m_Selected_Tool = 0;
99  m_FileFunction = NULL; // file function parameters
100 
102 
103  for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
104  m_Aperture_List[ii] = 0;
105 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
D_CODE * m_Aperture_List[TOOLS_MAX_COUNT]
Dcode (Aperture) List for this layer (max 999)
Definition: colors.h:49
GERBER_FILE_IMAGE::~GERBER_FILE_IMAGE ( )
virtual

Definition at line 108 of file class_gerber_file_image.cpp.

References DHEAD::DeleteAll(), DIM, m_Aperture_List, m_Drawings, and m_FileFunction.

109 {
111 
112  for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
113  {
114  delete m_Aperture_List[ii];
115  }
116 
117  delete m_FileFunction;
118 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
void DeleteAll()
Function DeleteAll deletes all items on the list and leaves the list empty.
Definition: dlist.cpp:41
D_CODE * m_Aperture_List[TOOLS_MAX_COUNT]
Dcode (Aperture) List for this layer (max 999)
DLIST< GERBER_DRAW_ITEM > m_Drawings

Member Function Documentation

void GERBER_FILE_IMAGE::AddMessageToList ( const wxString &  aMessage)
inline
void GERBER_FILE_IMAGE::Clear_GERBER_FILE_IMAGE ( )
void GERBER_FILE_IMAGE::ClearMessageList ( )
inline

Function ClearMessageList Clear the message list Call it before reading a Gerber file.

Definition at line 233 of file class_gerber_file_image.h.

Referenced by EXCELLON_IMAGE::LoadFile(), and LoadGerberFile().

234  {
235  m_messagesList.Clear();
236  }
int GERBER_FILE_IMAGE::DCodeNumber ( char *&  Text)

Definition at line 432 of file rs274d.cpp.

References IsNumber.

Referenced by Execute_G_Command(), LoadGerberFile(), and EXCELLON_IMAGE::TCodeNumber().

433 {
434  int ii = 0;
435  char* text;
436  char line[1024];
437 
438  if( Text == NULL )
439  return 0;
440 
441  Text++;
442  text = line;
443  while( IsNumber( *Text ) )
444  *(text++) = *(Text++);
445 
446  *text = 0;
447  ii = atoi( line );
448  return ii;
449 }
#define IsNumber(x)
void GERBER_FILE_IMAGE::DisplayImageInfo ( GERBVIEW_FRAME aMainFrame)

Function DisplayImageInfo has knowledge about the frame and how and where to put status information about this object into the frame's message panel.

Display info about Image Parameters.

Parameters
aMainFrame= the GERBVIEW_FRAME to display messages

Display info about Image Parameters. These parameters are valid for the entire file, and must set only once (If more than once, only the last value is used)

Definition at line 319 of file class_gerber_file_image.cpp.

References EDA_DRAW_FRAME::AppendMsgPanel(), BROWN, EDA_DRAW_FRAME::ClearMsgPanel(), CYAN, DARKRED, g_UserUnit, INCHES, m_GraphicLayer, m_ImageJustifyOffset, m_ImageJustifyXCenter, m_ImageJustifyYCenter, m_ImageName, m_ImageNegative, m_ImageRotation, wxPoint::x, and wxPoint::y.

Referenced by GERBVIEW_FRAME::OnLeftClick(), and GERBVIEW_FRAME::UpdateTitleAndInfo().

320 {
321  wxString msg;
322 
323  aMainFrame->ClearMsgPanel();
324 
325  // Display Image name (Image specific)
326  aMainFrame->AppendMsgPanel( _( "Image name" ), m_ImageName, CYAN );
327 
328  // Display graphic layer number used to draw this Image
329  // (not a Gerber parameter but is also image specific)
330  msg.Printf( wxT( "%d" ), m_GraphicLayer + 1 );
331  aMainFrame->AppendMsgPanel( _( "Graphic layer" ), msg, BROWN );
332 
333  // Display Image rotation (Image specific)
334  msg.Printf( wxT( "%d" ), m_ImageRotation );
335  aMainFrame->AppendMsgPanel( _( "Img Rot." ), msg, CYAN );
336 
337  // Display Image polarity (Image specific)
338  msg = m_ImageNegative ? _("Negative") : _("Normal");
339  aMainFrame->AppendMsgPanel( _( "Polarity" ), msg, BROWN );
340 
341  // Display Image justification and offset for justification (Image specific)
342  msg = m_ImageJustifyXCenter ? _("Center") : _("Normal");
343  aMainFrame->AppendMsgPanel( _( "X Justify" ), msg, DARKRED );
344 
345  msg = m_ImageJustifyYCenter ? _("Center") : _("Normal");
346  aMainFrame->AppendMsgPanel( _( "Y Justify" ), msg, DARKRED );
347 
348  if( g_UserUnit == INCHES )
349  msg.Printf( wxT( "X=%f Y=%f" ), Iu2Mils( m_ImageJustifyOffset.x ) / 1000.0,
350  Iu2Mils( m_ImageJustifyOffset.y ) / 1000.0 );
351  else
352  msg.Printf( wxT( "X=%f Y=%f" ), Iu2Millimeter( m_ImageJustifyOffset.x ),
353  Iu2Millimeter( m_ImageJustifyOffset.y ) );
354 
355  aMainFrame->AppendMsgPanel( _( "Image Justify Offset" ), msg, DARKRED );
356 }
Definition: colors.h:54
Definition: common.h:145
Definition: colors.h:59
EDA_UNITS_T g_UserUnit
Global variables definitions.
Definition: common.cpp:56
void AppendMsgPanel(const wxString &textUpper, const wxString &textLower, COLOR4D color, int pad=6)
Append a message to the message panel.
Definition: draw_frame.cpp:753
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:764
Definition: colors.h:62
bool GERBER_FILE_IMAGE::Execute_DCODE_Command ( char *&  text,
int  D_command 
)

Definition at line 577 of file rs274d.cpp.

References AddMessageToList(), DLIST< T >::Append(), APT_CIRCLE, fillArcGBRITEM(), fillArcPOLY(), fillFlashedGBRITEM(), fillLineGBRITEM(), FIRST_DCODE, GBR_POLYGON, GERB_INTERPOL_ARC_NEG, GERB_INTERPOL_ARC_POS, GERB_INTERPOL_LINEAR_001X, GERB_INTERPOL_LINEAR_01X, GERB_INTERPOL_LINEAR_10X, GERB_INTERPOL_LINEAR_1X, GetDCODE(), GetItemsList(), DLIST< T >::GetLast(), GetLayerParams(), m_360Arc_enbl, m_Current_Tool, m_CurrentPos, m_Drawings, GERBER_DRAW_ITEM::m_End, m_Exposure, GERBER_DRAW_ITEM::m_Flashed, m_IJPos, D_CODE::m_InUse, m_Iterpolation, m_Last_Pen_Command, D_CODE::m_Num_Dcode, GERBER_DRAW_ITEM::m_PolyCorners, m_PolygonFillMode, m_PolygonFillModeState, m_PreviousPos, GERBER_DRAW_ITEM::m_Shape, D_CODE::m_Shape, D_CODE::m_Size, GERBER_DRAW_ITEM::m_Start, StepAndRepeatItem(), and TOOLS_MAX_COUNT.

Referenced by LoadGerberFile().

578 {
579  wxSize size( 15, 15 );
580 
581  APERTURE_T aperture = APT_CIRCLE;
582  GERBER_DRAW_ITEM* gbritem;
583 
584  int dcode = 0;
585  D_CODE* tool = NULL;
586  wxString msg;
587 
588  if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command
589  {
590  if( D_commande > (TOOLS_MAX_COUNT - 1) )
591  D_commande = TOOLS_MAX_COUNT - 1;
592 
593  // remember which tool is selected, nothing is done with it in this
594  // call
595  m_Current_Tool = D_commande;
596 
597  D_CODE* pt_Dcode = GetDCODE( D_commande, false );
598  if( pt_Dcode )
599  pt_Dcode->m_InUse = true;
600 
601  return true;
602  }
603  else // D_commande = 0..9: this is a pen command (usually D1, D2 or D3)
604  {
605  m_Last_Pen_Command = D_commande;
606  }
607 
608  if( m_PolygonFillMode ) // Enter a polygon description:
609  {
610  switch( D_commande )
611  {
612  case 1: // code D01 Draw line, exposure ON
613  if( !m_Exposure ) // Start a new polygon outline:
614  {
615  m_Exposure = true;
616  gbritem = new GERBER_DRAW_ITEM( this );
617  m_Drawings.Append( gbritem );
618  gbritem->m_Shape = GBR_POLYGON;
619  gbritem->m_Flashed = false;
620  }
621 
622  switch( m_Iterpolation )
623  {
626  gbritem = m_Drawings.GetLast();
627 
628  fillArcPOLY( gbritem, m_PreviousPos,
630  ( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ? false : true,
631  m_360Arc_enbl, GetLayerParams().m_LayerNegative );
632  break;
633 
634  default:
635  gbritem = m_Drawings.GetLast();
636 
637  gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage
638  if( gbritem->m_PolyCorners.size() == 0 )
639  gbritem->m_PolyCorners.push_back( gbritem->m_Start );
640 
641  gbritem->m_End = m_CurrentPos; // m_End is used as temporary storage
642  gbritem->m_PolyCorners.push_back( gbritem->m_End );
643  break;
644  }
645 
648  break;
649 
650  case 2: // code D2: exposure OFF (i.e. "move to")
651  if( m_Exposure && GetItemsList() ) // End of polygon
652  {
653  gbritem = m_Drawings.GetLast();
654  StepAndRepeatItem( *gbritem );
655  }
656  m_Exposure = false;
659  break;
660 
661  default:
662  return false;
663  }
664  }
665  else
666  {
667  switch( D_commande )
668  {
669  case 1: // code D01 Draw line, exposure ON
670  m_Exposure = true;
671 
672  tool = GetDCODE( m_Current_Tool, false );
673  if( tool )
674  {
675  size = tool->m_Size;
676  dcode = tool->m_Num_Dcode;
677  aperture = tool->m_Shape;
678  }
679 
680  switch( m_Iterpolation )
681  {
683  gbritem = new GERBER_DRAW_ITEM( this );
684  m_Drawings.Append( gbritem );
685 
686  fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
687  m_CurrentPos, size, GetLayerParams().m_LayerNegative );
688  StepAndRepeatItem( *gbritem );
689  break;
690 
694  wxBell();
695  break;
696 
699  gbritem = new GERBER_DRAW_ITEM( this );
700  m_Drawings.Append( gbritem );
701 
702  fillArcGBRITEM( gbritem, dcode, m_PreviousPos,
703  m_CurrentPos, m_IJPos, size,
705  false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative );
706  StepAndRepeatItem( *gbritem );
707  break;
708 
709  default:
710  msg.Printf( wxT( "RS274D: DCODE Command: interpol error (type %X)" ),
711  m_Iterpolation );
712  AddMessageToList( msg );
713  break;
714  }
715 
717  break;
718 
719  case 2: // code D2: exposure OFF (i.e. "move to")
720  m_Exposure = false;
722  break;
723 
724  case 3: // code D3: flash aperture
725  tool = GetDCODE( m_Current_Tool, false );
726  if( tool )
727  {
728  size = tool->m_Size;
729  dcode = tool->m_Num_Dcode;
730  aperture = tool->m_Shape;
731  }
732 
733  gbritem = new GERBER_DRAW_ITEM( this );
734  m_Drawings.Append( gbritem );
735  fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
736  size, GetLayerParams().m_LayerNegative );
737  StepAndRepeatItem( *gbritem );
739  break;
740 
741  default:
742  return false;
743  }
744  }
745 
746  return true;
747 }
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:98
static void fillArcPOLY(GERBER_DRAW_ITEM *aGbrItem, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &rel_center, bool aClockwise, bool aMultiquadrant, bool aLayerNegative)
Function fillArcPOLY creates an arc G code when found in poly outlines.
Definition: rs274d.cpp:335
bool m_InUse
false if the aperure (previously defined) is not used to draw something
Definition: dcode.h:106
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:99
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
std::vector< wxPoint > m_PolyCorners
D_CODE * GetDCODE(int aDCODE, bool aCreateIfNoExist=true)
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE...
void fillLineGBRITEM(GERBER_DRAW_ITEM *aGbrItem, int Dcode_index, const wxPoint &aStart, const wxPoint &aEnd, wxSize aPenSize, bool aLayerNegative)
Function fillLineGBRITEM initializes a given GBRITEM so that it can draw a linear D code...
Definition: rs274d.cpp:159
T * GetLast() const
Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:170
#define FIRST_DCODE
Definition: dcode.h:70
APERTURE_T
Enum APERTURE_T is the set of all gerber aperture types allowed, according to page 16 of http://gerbv...
Definition: dcode.h:49
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:100
bool m_Exposure
whether an aperture macro tool is flashed on or off
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
void fillFlashedGBRITEM(GERBER_DRAW_ITEM *aGbrItem, APERTURE_T aAperture, int Dcode_index, const wxPoint &aPos, wxSize aSize, bool aLayerNegative)
Function fillFlashedGBRITEM initializes a given GBRITEM so that it can draw a circle which is filled ...
Definition: rs274d.cpp:107
DLIST< GERBER_DRAW_ITEM > m_Drawings
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
static void fillArcGBRITEM(GERBER_DRAW_ITEM *aGbrItem, int Dcode_index, const wxPoint &aStart, const wxPoint &aEnd, const wxPoint &aRelCenter, wxSize aPenSize, bool aClockwise, bool aMultiquadrant, bool aLayerNegative)
Function fillArcGBRITEM initializes a given GBRITEM so that it can draw an arc G code.
Definition: rs274d.cpp:208
void StepAndRepeatItem(const GERBER_DRAW_ITEM &aItem)
Function StepAndRepeatItem Gerber format has a command Step an Repeat This function must be called wh...
GERBER_LAYER & GetLayerParams()
Function GetLayerParams.
bool GERBER_FILE_IMAGE::Execute_G_Command ( char *&  text,
int  G_command 
)

Definition at line 452 of file rs274d.cpp.

References AddMessageToList(), DCodeNumber(), dummy(), FIRST_DCODE, GC_CIRCLE_NEG_INTERPOL, GC_CIRCLE_POS_INTERPOL, GC_COMMENT, GC_LINEAR_INTERPOL_0P01X, GC_LINEAR_INTERPOL_0P1X, GC_LINEAR_INTERPOL_10X, GC_LINEAR_INTERPOL_1X, GC_MOVE, GC_PHOTO_MODE, GC_SELECT_TOOL, GC_SPECIFY_ABSOLUES_COORD, GC_SPECIFY_INCHES, GC_SPECIFY_MILLIMETERS, GC_SPECIFY_RELATIVEES_COORD, GC_TURN_OFF_360_INTERPOL, GC_TURN_OFF_POLY_FILL, GC_TURN_ON_360_INTERPOL, GC_TURN_ON_POLY_FILL, GERB_INTERPOL_ARC_NEG, GERB_INTERPOL_ARC_POS, GERB_INTERPOL_LINEAR_001X, GERB_INTERPOL_LINEAR_01X, GERB_INTERPOL_LINEAR_10X, GERB_INTERPOL_LINEAR_1X, GetDCODE(), GetItemsList(), DLIST< T >::GetLast(), X2_ATTRIBUTE::IsFileFunction(), m_360Arc_enbl, m_Current_File, m_Current_Tool, m_Drawings, m_Exposure, m_FileFunction, m_GerbMetric, D_CODE::m_InUse, m_Iterpolation, m_PolygonFillMode, m_PolygonFillModeState, m_Relative, X2_ATTRIBUTE::ParseAttribCmd(), StepAndRepeatItem(), and TOOLS_MAX_COUNT.

Referenced by LoadGerberFile().

453 {
454 // D( printf( "%22s: G_CODE<%d>\n", __func__, G_command ); )
455 
456  switch( G_command )
457  {
458  case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can
459  // be safely ignored
460  break;
461 
464  break;
465 
468  break;
469 
472  break;
473 
474  case GC_COMMENT:
475  // Skip comment, but only if the line does not start by "G04 #@! TF"
476  // which is a metadata
477  if( strncmp( text, " #@! TF", 7 ) == 0 )
478  {
479  text += 7;
481  dummy.ParseAttribCmd( m_Current_File, NULL, 0, text );
482  if( dummy.IsFileFunction() )
483  {
484  delete m_FileFunction;
486  }
487  }
488 
489  while ( *text && (*text != '*') )
490  text++;
491  break;
492 
495  break;
496 
499  break;
500 
503  break;
504 
505  case GC_SELECT_TOOL:
506  {
507  int D_commande = DCodeNumber( text );
508  if( D_commande < FIRST_DCODE )
509  return false;
510  if( D_commande > (TOOLS_MAX_COUNT - 1) )
511  D_commande = TOOLS_MAX_COUNT - 1;
512  m_Current_Tool = D_commande;
513  D_CODE* pt_Dcode = GetDCODE( D_commande, false );
514  if( pt_Dcode )
515  pt_Dcode->m_InUse = true;
516  break;
517  }
518 
519  case GC_SPECIFY_INCHES:
520  m_GerbMetric = false; // false = Inches, true = metric
521  break;
522 
524  m_GerbMetric = true; // false = Inches, true = metric
525  break;
526 
527  case GC_TURN_OFF_360_INTERPOL: // disable Multi cadran arc and Arc interpol
528  m_360Arc_enbl = false;
529  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // not sure it should be done
530  break;
531 
533  m_360Arc_enbl = true;
534  break;
535 
537  m_Relative = false; // false = absolute Coord, true = relative
538  // Coord
539  break;
540 
542  m_Relative = true; // false = absolute Coord, true = relative
543  // Coord
544  break;
545 
547  m_PolygonFillMode = true;
548  m_Exposure = false;
549  break;
550 
552  if( m_Exposure && GetItemsList() ) // End of polygon
553  {
554  GERBER_DRAW_ITEM * gbritem = m_Drawings.GetLast();
555  StepAndRepeatItem( *gbritem );
556  }
557  m_Exposure = false;
558  m_PolygonFillMode = false;
560  break;
561 
562  case GC_MOVE: // Non existent
563  default:
564  {
565  wxString msg;
566  msg.Printf( wxT( "G%0.2d command not handled" ), G_command );
567  AddMessageToList( msg );
568  return false;
569  }
570  }
571 
572 
573  return true;
574 }
class X2_ATTRIBUTE_FILEFUNCTION ( from TF.FileFunction in Gerber file) Example file function: TF...
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
class X2_ATTRIBUTE The attribute value consists of a number of substrings separated by a comma ...
bool m_InUse
false if the aperure (previously defined) is not used to draw something
Definition: dcode.h:106
D_CODE * GetDCODE(int aDCODE, bool aCreateIfNoExist=true)
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE...
T * GetLast() const
Function GetLast returns the last T* in the list without removing it, or NULL if the list is empty...
Definition: dlist.h:170
#define FIRST_DCODE
Definition: dcode.h:70
int DCodeNumber(char *&Text)
Definition: rs274d.cpp:432
bool ParseAttribCmd(FILE *aFile, char *aBuffer, int aBuffSize, char *&aText)
parse a TF command terminated with a % and fill m_Prms by the parameters found.
bool IsFileFunction()
return true if the attribute is .FileFunction
bool m_Exposure
whether an aperture macro tool is flashed on or off
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
DLIST< GERBER_DRAW_ITEM > m_Drawings
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
void StepAndRepeatItem(const GERBER_DRAW_ITEM &aItem)
Function StepAndRepeatItem Gerber format has a command Step an Repeat This function must be called wh...
bool GERBER_FILE_IMAGE::ExecuteRS274XCommand ( int  command,
char *  aBuff,
char *&  text 
)

Function ExecuteRS274XCommand executes 1 command.

Definition at line 245 of file rs274x.cpp.

References AddMessageToList(), AP_DEFINITION, AP_MACRO, APERTURE_ATTRIBUTE, D_CODE::AppendParam(), APT_CIRCLE, APT_DEF_RECT_HOLE, APT_DEF_ROUND_HOLE, APT_MACRO, APT_OVAL, APT_POLYGON, APT_RECT, AXIS_SELECT, DBG, dummy(), FILE_ATTRIBUTE, FindApertureMacro(), FORMAT_STATEMENT, fromGerberString(), GBR_NETLIST_METADATA::GBR_NETINFO_CMP, GBR_NETLIST_METADATA::GBR_NETINFO_NET, GBR_NETLIST_METADATA::GBR_NETINFO_PAD, GERB_INTERPOL_LINEAR_1X, GERBER_BUFZ, X2_ATTRIBUTE::GetAttribute(), GetDCODE(), GetEndOfBlock(), GetLayerParams(), X2_ATTRIBUTE::GetPrm(), X2_ATTRIBUTE::GetPrmCount(), IMAGE_JUSTIFY, IMAGE_NAME, IMAGE_OFFSET, IMAGE_POLARITY, IMAGE_ROTATION, INCH, X2_ATTRIBUTE::IsFileFunction(), X2_ATTRIBUTE::IsFileMD5(), X2_ATTRIBUTE::IsFilePart(), KiROUND(), KNOCKOUT, LAYER_NAME, LAYER_POLARITY, D_CODE::m_AperFunction, m_AperFunction, GBR_NETLIST_METADATA::m_Cmpref, m_Current_File, m_DecimalFormat, D_CODE::m_Defined, D_CODE::m_Drill, D_CODE::m_DrillShape, D_CODE::m_EdgesCount, m_FileFunction, m_FmtLen, m_FmtScale, m_GerbMetric, m_Has_DCode, m_ImageJustifyOffset, m_ImageJustifyXCenter, m_ImageJustifyYCenter, m_ImageName, m_ImageNegative, m_ImageOffset, m_ImageRotation, m_IsX2_file, m_Iterpolation, GERBER_LAYER::m_LayerName, GERBER_LAYER::m_LayerNegative, m_LocalRotation, m_MD5_value, m_MirrorA, m_MirrorB, GBR_NETLIST_METADATA::m_NetAttribType, m_NetAttributeDict, GBR_NETLIST_METADATA::m_Netname, m_NoTrailingZeros, m_Offset, GBR_NETLIST_METADATA::m_Padname, m_PartString, m_Relative, D_CODE::m_Rotation, m_Scale, D_CODE::m_Shape, D_CODE::m_Size, GERBER_LAYER::m_StepForRepeat, GERBER_LAYER::m_StepForRepeatMetric, m_SwapAxis, GERBER_LAYER::m_XRepeatCount, GERBER_LAYER::m_YRepeatCount, MILLIMETER, MIRROR_IMAGE, MODE_OF_UNITS, APERTURE_MACRO::name, NET_ATTRIBUTE, OFFSET, X2_ATTRIBUTE::ParseAttribCmd(), ReadApertureMacro(), ReadDouble(), ReadInt(), ReadXCommand(), REMOVE_APERTURE_ATTRIBUTE, RemoveAttribute(), ROTATE, SCALE_FACTOR, D_CODE::SetMacro(), STEP_AND_REPEAT, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by ReadRS274XCommand().

246 {
247  int code;
248  int seq_len; // not used, just provided
249  int seq_char;
250  bool ok = true;
251  wxString msg;
252  double fcoord;
253  bool x_fmt_known = false;
254  bool y_fmt_known = false;
255 
256  // conv_scale = scaling factor from inch to Internal Unit
257  double conv_scale = IU_PER_MILS * 1000;
258  if( m_GerbMetric )
259  conv_scale /= 25.4;
260 
261 // DBG( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); )
262 
263  switch( command )
264  {
265  case FORMAT_STATEMENT:
266  seq_len = 2;
267 
268  while( *text != '*' )
269  {
270  switch( *text )
271  {
272  case ' ':
273  text++;
274  break;
275 
276  case 'L': // No Leading 0
277  m_DecimalFormat = false;
278  m_NoTrailingZeros = false;
279  text++;
280  break;
281 
282  case 'T': // No trailing 0
283  m_DecimalFormat = false;
284  m_NoTrailingZeros = true;
285  text++;
286  break;
287 
288  case 'A': // Absolute coord
289  m_Relative = false;
290  text++;
291  break;
292 
293  case 'I': // Relative coord
294  m_Relative = true;
295  text++;
296  break;
297 
298  case 'G':
299  case 'N': // Sequence code (followed by one digit: the sequence len)
300  // (sometimes found before the X,Y sequence)
301  // Obscure option
302  text++;
303  seq_char = *text++;
304  if( (seq_char >= '0') && (seq_char <= '9') )
305  seq_len = seq_char - '0';
306  break;
307 
308  case 'D':
309  case 'M': // Sequence code (followed by one digit: the sequence len)
310  // (sometimes found after the X,Y sequence)
311  // Obscure option
312  code = *text++;
313  if( ( *text >= '0' ) && ( *text<= '9' ) )
314  text++; // skip the digit
315  else if( code == 'D' )
316  // Decimal format: sometimes found, but not really documented
317  m_DecimalFormat = true;
318  break;
319 
320  case 'X':
321  case 'Y':
322  {
323  code = *(text++);
324  char ctmp = *(text++) - '0';
325  if( code == 'X' )
326  {
327  x_fmt_known = true;
328  // number of digits after the decimal point (0 to 7 allowed)
329  m_FmtScale.x = *text - '0';
330  m_FmtLen.x = ctmp + m_FmtScale.x;
331 
332  // m_FmtScale is 0 to 7
333  // (Old Gerber specification was 0 to 6)
334  if( m_FmtScale.x < 0 )
335  m_FmtScale.x = 0;
336  if( m_FmtScale.x > 7 )
337  m_FmtScale.x = 7;
338  }
339  else
340  {
341  y_fmt_known = true;
342  m_FmtScale.y = *text - '0';
343  m_FmtLen.y = ctmp + m_FmtScale.y;
344  if( m_FmtScale.y < 0 )
345  m_FmtScale.y = 0;
346  if( m_FmtScale.y > 7 )
347  m_FmtScale.y = 7;
348  }
349  text++;
350  }
351  break;
352 
353  case '*':
354  break;
355 
356  default:
357  msg.Printf( wxT( "Unknown id (%c) in FS command" ),
358  *text );
359  AddMessageToList( msg );
360  GetEndOfBlock( buff, text, m_Current_File );
361  ok = false;
362  break;
363  }
364  }
365  if( !x_fmt_known || !y_fmt_known )
366  AddMessageToList( wxT( "RS274X: Format Statement (FS) without X or Y format" ) );
367 
368  break;
369 
370  case AXIS_SELECT: // command ASAXBY*% or %ASAYBX*%
371  m_SwapAxis = false;
372  if( strncasecmp( text, "AYBX", 4 ) == 0 )
373  m_SwapAxis = true;
374  break;
375 
376  case MIRROR_IMAGE: // command %MIA0B0*%, %MIA0B1*%, %MIA1B0*%, %MIA1B1*%
377  m_MirrorA = m_MirrorB = 0;
378  while( *text && *text != '*' )
379  {
380  switch( *text )
381  {
382  case 'A': // Mirror A axis ?
383  text++;
384  if( *text == '1' )
385  m_MirrorA = true;
386  break;
387 
388  case 'B': // Mirror B axis ?
389  text++;
390  if( *text == '1' )
391  m_MirrorB = true;
392  break;
393 
394  default:
395  text++;
396  break;
397  }
398  }
399  break;
400 
401  case MODE_OF_UNITS:
402  code = ReadXCommand( text );
403  if( code == INCH )
404  m_GerbMetric = false;
405  else if( code == MILLIMETER )
406  m_GerbMetric = true;
407  conv_scale = m_GerbMetric ? IU_PER_MILS / 25.4 : IU_PER_MILS;
408  break;
409 
410  case FILE_ATTRIBUTE: // Command %TF ...
411  m_IsX2_file = true;
412  {
414  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
415 
416  if( dummy.IsFileFunction() )
417  {
418  delete m_FileFunction;
420  }
421  else if( dummy.IsFileMD5() )
422  {
423  m_MD5_value = dummy.GetPrm( 1 );
424  }
425  else if( dummy.IsFilePart() )
426  {
427  m_PartString = dummy.GetPrm( 1 );
428  }
429  }
430  break;
431 
432  case APERTURE_ATTRIBUTE: // Command %TA ... Not yet supported
433  {
435  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
436 
437  if( dummy.GetAttribute() == ".AperFunction" )
438  {
439  m_AperFunction = dummy.GetPrm( 1 );
440 
441  // A few function values can have other parameters. Add them
442  for( int ii = 2; ii < dummy.GetPrmCount(); ii++ )
443  m_AperFunction << "," << dummy.GetPrm( ii );
444  }
445  }
446  break;
447 
448  case NET_ATTRIBUTE: // Command %TO currently %TO.P %TO.N and %TO.C
449  {
451 
452  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
453 
454  if( dummy.GetAttribute() == ".N" )
455  {
458  }
459  else if( dummy.GetAttribute() == ".C" )
460  {
463  }
464  else if( dummy.GetAttribute() == ".P" )
465  {
469  }
470  }
471  break;
472 
473  case REMOVE_APERTURE_ATTRIBUTE: // Command %TD ...
474  {
476  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
477  RemoveAttribute( dummy );
478  }
479  break;
480 
481  case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset
482  m_Offset.x = m_Offset.y = 0;
483  while( *text != '*' )
484  {
485  switch( *text )
486  {
487  case 'A': // A axis offset in current unit (inch or mm)
488  text++;
489  fcoord = ReadDouble( text );
490  m_Offset.x = KiROUND( fcoord * conv_scale );
491  break;
492 
493  case 'B': // B axis offset in current unit (inch or mm)
494  text++;
495  fcoord = ReadDouble( text );
496  m_Offset.y = KiROUND( fcoord * conv_scale );
497  break;
498  }
499  }
500  break;
501 
502  case SCALE_FACTOR:
503  m_Scale.x = m_Scale.y = 1.0;
504  while( *text != '*' )
505  {
506  switch( *text )
507  {
508  case 'A': // A axis scale
509  text++;
510  m_Scale.x = ReadDouble( text );
511  break;
512 
513  case 'B': // B axis scale
514  text++;
515  m_Scale.y = ReadDouble( text );
516  break;
517  }
518  }
519  break;
520 
521  case IMAGE_OFFSET: // command: IOAnnBnn (nn = float number) = Image Offset
523  while( *text != '*' )
524  {
525  switch( *text )
526  {
527  case 'A': // A axis offset in current unit (inch or mm)
528  text++;
529  fcoord = ReadDouble( text );
530  m_ImageOffset.x = KiROUND( fcoord * conv_scale );
531  break;
532 
533  case 'B': // B axis offset in current unit (inch or mm)
534  text++;
535  fcoord = ReadDouble( text );
536  m_ImageOffset.y = KiROUND( fcoord * conv_scale );
537  break;
538  }
539  }
540  break;
541 
542  case IMAGE_ROTATION: // command IR0* or IR90* or IR180* or IR270*
543  if( strncasecmp( text, "0*", 2 ) == 0 )
544  m_ImageRotation = 0;
545  else if( strncasecmp( text, "90*", 3 ) == 0 )
546  m_ImageRotation = 90;
547  else if( strncasecmp( text, "180*", 4 ) == 0 )
548  m_ImageRotation = 180;
549  else if( strncasecmp( text, "270*", 4 ) == 0 )
550  m_ImageRotation = 270;
551  else
552  AddMessageToList( _( "RS274X: Command \"IR\" rotation value not allowed" ) );
553  break;
554 
555  case STEP_AND_REPEAT: // command SR, like %SRX3Y2I5.0J2*%
556  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
558  GetLayerParams().m_StepForRepeat.x = 0.0; // offset for Step and Repeat command
560  GetLayerParams().m_YRepeatCount = 1; // The repeat count
561  GetLayerParams().m_StepForRepeatMetric = m_GerbMetric; // the step units
562  while( *text && *text != '*' )
563  {
564  switch( *text )
565  {
566  case 'I': // X axis offset
567  text++;
569  break;
570 
571  case 'J': // Y axis offset
572  text++;
574  break;
575 
576  case 'X': // X axis repeat count
577  text++;
579  break;
580 
581  case 'Y': // Y axis offset
582  text++;
584  break;
585  default:
586  text++;
587  break;
588  }
589  }
590  break;
591 
592  case IMAGE_JUSTIFY: // Command IJAnBn*
593  m_ImageJustifyXCenter = false; // Image Justify Center on X axis (default = false)
594  m_ImageJustifyYCenter = false; // Image Justify Center on Y axis (default = false)
595  m_ImageJustifyOffset = wxPoint(0,0); // Image Justify Offset on XY axis (default = 0,0)
596  while( *text && *text != '*' )
597  {
598  // IJ command is (for A or B axis) AC or AL or A<coordinate>
599  switch( *text )
600  {
601  case 'A': // A axis justify
602  text++;
603  if( *text == 'C' )
604  {
605  m_ImageJustifyXCenter = true;
606  text++;
607  }
608  else if( *text == 'L' )
609  {
610  m_ImageJustifyXCenter = true;
611  text++;
612  }
613  else m_ImageJustifyOffset.x = KiROUND( ReadDouble( text ) * conv_scale);
614  break;
615 
616  case 'B': // B axis justify
617  text++;
618  if( *text == 'C' )
619  {
620  m_ImageJustifyYCenter = true;
621  text++;
622  }
623  else if( *text == 'L' )
624  {
625  m_ImageJustifyYCenter = true;
626  text++;
627  }
628  else m_ImageJustifyOffset.y = KiROUND( ReadDouble( text ) * conv_scale);
629  break;
630  default:
631  text++;
632  break;
633  }
634  }
639  break;
640 
641  case KNOCKOUT:
642  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
643  msg = _( "RS274X: Command KNOCKOUT ignored by GerbView" ) ;
644  AddMessageToList( msg );
645  break;
646 
647  case ROTATE: // Layer rotation: command like %RO45*%
648  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
649  m_LocalRotation =ReadDouble( text ); // Store layer rotation in degrees
650  break;
651 
652  case IMAGE_NAME:
653  m_ImageName.Empty();
654  while( *text != '*' )
655  {
656  m_ImageName.Append( *text++ );
657  }
658 
659  break;
660 
661  case LAYER_NAME:
662  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
663  GetLayerParams( ).m_LayerName.Empty();
664  while( *text != '*' )
665  {
666  GetLayerParams( ).m_LayerName.Append( *text++ );
667  }
668 
669  break;
670 
671  case IMAGE_POLARITY:
672  if( strncasecmp( text, "NEG", 3 ) == 0 )
673  m_ImageNegative = true;
674  else
675  m_ImageNegative = false;
676  DBG( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__,
677  m_ImageNegative ? "true" : "false" ); )
678  break;
679 
680  case LAYER_POLARITY:
681  if( *text == 'C' )
683  else
685 
686  break;
687 
688  case AP_MACRO: // lines like %AMMYMACRO*
689  // 5,1,8,0,0,1.08239X$1,22.5*
690  // %
691  /*ok = */ReadApertureMacro( buff, text, m_Current_File );
692  break;
693 
694  case AP_DEFINITION:
695  /* input example: %ADD30R,0.081800X0.101500*%
696  * Aperture definition has 4 options: C, R, O, P
697  * (Circle, Rect, Oval, regular Polygon)
698  * and shapes can have a hole (round or rectangular).
699  * All optional parameters values start by X
700  * at this point, text points to 2nd 'D'
701  */
702  if( *text++ != 'D' )
703  {
704  ok = false;
705  break;
706  }
707 
708  m_Has_DCode = true;
709 
710  code = ReadInt( text );
711 
712  D_CODE* dcode;
713  dcode = GetDCODE( code );
714 
715  if( dcode == NULL )
716  break;
717 
719 
720  // at this point, text points to character after the ADD<num>,
721  // i.e. R in example above. If text[0] is one of the usual
722  // apertures: (C,R,O,P), there is a comma after it.
723  if( text[1] == ',' )
724  {
725  char stdAperture = *text;
726 
727  text += 2; // skip "C," for example
728 
729  dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale );
730  dcode->m_Size.y = dcode->m_Size.x;
731 
732  switch( stdAperture ) // Aperture desceiption has optional parameters. Read them
733  {
734  case 'C': // Circle
735  dcode->m_Shape = APT_CIRCLE;
736  while( *text == ' ' )
737  text++;
738 
739  if( *text == 'X' )
740  {
741  text++;
742  dcode->m_Drill.x = dcode->m_Drill.y =
743  KiROUND( ReadDouble( text ) * conv_scale );
745  }
746 
747  while( *text == ' ' )
748  text++;
749 
750  if( *text == 'X' )
751  {
752  text++;
753  dcode->m_Drill.y =
754  KiROUND( ReadDouble( text ) * conv_scale );
755 
757  }
758  dcode->m_Defined = true;
759  break;
760 
761  case 'O': // oval
762  case 'R': // rect
763  dcode->m_Shape = (stdAperture == 'O') ? APT_OVAL : APT_RECT;
764 
765  while( *text == ' ' )
766  text++;
767 
768  if( *text == 'X' )
769  {
770  text++;
771  dcode->m_Size.y =
772  KiROUND( ReadDouble( text ) * conv_scale );
773  }
774 
775  while( *text == ' ' )
776  text++;
777 
778  if( *text == 'X' )
779  {
780  text++;
781  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
782  dcode->m_Drill.y = dcode->m_Drill.x;
784  }
785 
786  while( *text == ' ' )
787  text++;
788 
789  if( *text == 'X' )
790  {
791  text++;
792  dcode->m_Drill.y =
793  KiROUND( ReadDouble( text ) * conv_scale );
795  }
796  dcode->m_Defined = true;
797  break;
798 
799  case 'P':
800 
801  /* Regular polygon: a command line like %ADD12P,0.040X10X25X0.025X0.025X0.0150*%
802  * params are: <diameter>, X<edge count>, X<Rotation>, X<X hole dim>, X<Y hole dim>
803  */
804  dcode->m_Shape = APT_POLYGON;
805  while( *text == ' ' )
806  text++;
807 
808  if( *text == 'X' )
809  {
810  text++;
811  dcode->m_EdgesCount = ReadInt( text );
812  }
813 
814  while( *text == ' ' )
815  text++;
816 
817  if( *text == 'X' )
818  {
819  text++;
820  dcode->m_Rotation = ReadDouble( text );
821  }
822 
823  while( *text == ' ' )
824  text++;
825 
826  if( *text == 'X' )
827  {
828  text++;
829  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
830  dcode->m_Drill.y = dcode->m_Drill.x =
832  }
833 
834  while( *text == ' ' )
835  text++;
836 
837  if( *text == 'X' )
838  {
839  text++;
840  dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale );
842  }
843  dcode->m_Defined = true;
844  break;
845  }
846  }
847  else // text[0] starts an aperture macro name
848  {
849  APERTURE_MACRO am_lookup;
850 
851  while( *text && *text != '*' && *text != ',' )
852  am_lookup.name.Append( *text++ );
853 
854  // When an aperture definition is like %AMLINE2* 22,1,$1,$2,0,0,-45*
855  // the ADDxx<MACRO_NAME> command has parameters, like %ADD14LINE2,0.8X0.5*%
856  if( *text == ',' )
857  { // Read aperture macro parameters and store them
858  text++; // text points the first parameter
859 
860  while( *text && *text != '*' )
861  {
862  double param = ReadDouble( text );
863  dcode->AppendParam( param );
864 
865  while( isspace( *text ) )
866  text++;
867 
868  // Skip 'X' separator:
869  if( *text == 'X' || *text == 'x' )
870  text++;
871  }
872  }
873 
874  // lookup the aperture macro here.
875  APERTURE_MACRO* pam = FindApertureMacro( am_lookup );
876 
877  if( !pam )
878  {
879  msg.Printf( wxT( "RS274X: aperture macro %s not found\n" ),
880  TO_UTF8( am_lookup.name ) );
881  AddMessageToList( msg );
882  ok = false;
883  break;
884  }
885 
886  dcode->m_Shape = APT_MACRO;
887  dcode->SetMacro( pam );
888  }
889 
890  break;
891 
892  default:
893  ok = false;
894  break;
895  }
896 
897  (void) seq_len; // quiet g++, or delete the unused variable.
898 
899  ok = GetEndOfBlock( buff, text, m_Current_File );
900 
901  return ok;
902 }
class X2_ATTRIBUTE_FILEFUNCTION ( from TF.FileFunction in Gerber file) Example file function: TF...
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
class X2_ATTRIBUTE The attribute value consists of a number of substrings separated by a comma ...
wxString name
The name of the aperture macro.
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
print info associated to a component (TO.C attribute)
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:98
int ReadInt(char *&text, bool aSkipSeparator=true)
Function ReadInt reads an int from an ASCII character buffer.
Definition: dcode.h:52
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:99
double m_Rotation
shape rotation in degrees
Definition: dcode.h:103
wxSize m_Drill
dimension of the hole (if any) (draill file)
Definition: dcode.h:101
wxRealPoint m_StepForRepeat
D_CODE * GetDCODE(int aDCODE, bool aCreateIfNoExist=true)
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE...
wxString m_Cmpref
the component reference parent of the data
bool ReadApertureMacro(char *aBuff, char *&text, FILE *gerber_file)
Function ReadApertureMacro reads in an aperture macro and saves it in m_aperture_macros.
Definition: rs274x.cpp:967
const wxString & GetPrm(int aIdx)
Definition: dcode.h:51
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
double ReadDouble(char *&text, bool aSkipSeparator=true)
Function ReadDouble reads a double from an ASCII character buffer.
bool IsFileMD5()
return true if the attribute is .MD5
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:108
bool GetEndOfBlock(char *buff, char *&text, FILE *gerber_file)
Definition: rs274x.cpp:905
wxString m_Padname
for a flashed pad: the pad name ((TO.P attribute)
void AppendParam(double aValue)
AppendParam() Add a parameter to the D_CODE parameter list.
Definition: dcode.h:123
bool IsFilePart()
return true if the attribute is .Part
bool ParseAttribCmd(FILE *aFile, char *aBuffer, int aBuffSize, char *&aText)
parse a TF command terminated with a % and fill m_Prms by the parameters found.
wxString m_Netname
for items associated to a net: the netname
APERTURE_MACRO * FindApertureMacro(const APERTURE_MACRO &aLookup)
Function FindApertureMacro looks up a previously read in aperture macro.
static const wxString fromGerberString(const wxString &aGbrString)
Convert a string read from a gerber file to an unicode string Usual chars (ASCII7 values) are the onl...
Definition: rs274x.cpp:156
bool IsFileFunction()
return true if the attribute is .FileFunction
wxString m_AperFunction
the aperture attribute (created by a TA.AperFunction command) attached to the D_CODE ...
Definition: dcode.h:109
void RemoveAttribute(X2_ATTRIBUTE &aAttribute)
Function RemoveAttribute.
APERTURE_DEF_HOLETYPE m_DrillShape
shape of the hole (0 = no hole, round = 1, rect = 2) */
Definition: dcode.h:102
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
static LIB_PART * dummy()
Used when a LIB_PART is not found in library to draw a dummy shape This component is a 400 mils squar...
Definition: rs274x.cpp:63
GBR_NETLIST_METADATA m_NetAttributeDict
void SetMacro(APERTURE_MACRO *aMacro)
Definition: dcode.h:152
int m_EdgesCount
in aperture definition Polygon only: number of edges for the polygon
Definition: dcode.h:104
const wxString & GetAttribute()
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
print info associated to a flashed pad (TO.P attribute)
#define DBG(x)
Definition: fctsys.h:33
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
print info associated to a net (TO.N attribute)
static int ReadXCommand(char *&text)
Function ReadXCommand reads in two bytes of data and assembles them into an int with the first byte i...
Definition: rs274x.cpp:123
GERBER_LAYER & GetLayerParams()
Function GetLayerParams.
int m_NetAttribType
the type of net info (used to define the gerber string to create)
APERTURE_MACRO * GERBER_FILE_IMAGE::FindApertureMacro ( const APERTURE_MACRO aLookup)

Function FindApertureMacro looks up a previously read in aperture macro.

Parameters
aLookupA dummy APERTURE_MACRO with [only] the name field set.
Returns
APERTURE_MACRO* - the one with a matching name, or NULL if not found.

Definition at line 149 of file class_gerber_file_image.cpp.

References m_aperture_macros.

Referenced by ExecuteRS274XCommand().

150 {
151  APERTURE_MACRO_SET::iterator iter = m_aperture_macros.find( aLookup );
152 
153  if( iter != m_aperture_macros.end() )
154  {
155  APERTURE_MACRO* pam = (APERTURE_MACRO*) &(*iter);
156  return pam;
157  }
158 
159  return NULL; // not found
160 }
APERTURE_MACRO_SET m_aperture_macros
a collection of APERTURE_MACROS, sorted by name
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
int GERBER_FILE_IMAGE::GCodeNumber ( char *&  Text)

Definition at line 409 of file rs274d.cpp.

References IsNumber.

Referenced by LoadGerberFile().

410 {
411  int ii = 0;
412  char* text;
413  char line[1024];
414 
415  if( Text == NULL )
416  return 0;
417  Text++;
418  text = line;
419  while( IsNumber( *Text ) )
420  {
421  *(text++) = *(Text++);
422  }
423 
424  *text = 0;
425  ii = atoi( line );
426  return ii;
427 }
#define IsNumber(x)
D_CODE * GERBER_FILE_IMAGE::GetDCODE ( int  aDCODE,
bool  aCreateIfNoExist = true 
)

Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE.

Parameters
aDCODEThe numeric value of the D_CODE to look up.
aCreateIfNoExistIf true, then create the D_CODE if it does not exist in list.
Returns
D_CODE* - the one implied by the given aDCODE, or NULL if the requested aDCODE is out of range.

Definition at line 129 of file class_gerber_file_image.cpp.

References DIM, FIRST_DCODE, and m_Aperture_List.

Referenced by Execute_DCODE_Command(), EXCELLON_IMAGE::Execute_Drill_Command(), Execute_G_Command(), ExecuteRS274XCommand(), GERBER_DRAW_ITEM::GetDcodeDescr(), GERBVIEW_FRAME::Liste_D_Codes(), EXCELLON_IMAGE::readToolInformation(), EXCELLON_IMAGE::Select_Tool(), GERBVIEW_FRAME::updateAperAttributesSelectBox(), and GERBVIEW_FRAME::updateDCodeSelectBox().

130 {
131  unsigned ndx = aDCODE - FIRST_DCODE;
132 
133  if( ndx < (unsigned) DIM( m_Aperture_List ) )
134  {
135  // lazily create the D_CODE if it does not exist.
136  if( aCreateIfNoExist )
137  {
138  if( m_Aperture_List[ndx] == NULL )
139  m_Aperture_List[ndx] = new D_CODE( ndx + FIRST_DCODE );
140  }
141 
142  return m_Aperture_List[ndx];
143  }
144 
145  return NULL;
146 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
D_CODE * m_Aperture_List[TOOLS_MAX_COUNT]
Dcode (Aperture) List for this layer (max 999)
#define FIRST_DCODE
Definition: dcode.h:70
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
int GERBER_FILE_IMAGE::GetDcodesCount ( )
Returns
the count of Dcode tools in used by the image

Definition at line 245 of file class_gerber_file_image.cpp.

References DIM, m_Aperture_List, and m_InUse.

Referenced by GERBVIEW_FRAME::Liste_D_Codes(), GERBVIEW_FRAME::updateAperAttributesSelectBox(), and GERBVIEW_FRAME::updateDCodeSelectBox().

246 {
247  int count = 0;
248 
249  for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
250  {
251  if( m_Aperture_List[ii] )
252  if( m_Aperture_List[ii]->m_InUse || m_Aperture_List[ii]->m_Defined )
253  ++count;
254  }
255 
256  return count;
257 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
D_CODE * m_Aperture_List[TOOLS_MAX_COUNT]
Dcode (Aperture) List for this layer (max 999)
GERBER_LAYER& GERBER_FILE_IMAGE::GetLayerParams ( )
inline

Function GetLayerParams.

Returns
the current layers params

Definition at line 215 of file class_gerber_file_image.h.

References m_GBRLayerParams.

Referenced by Execute_DCODE_Command(), ExecuteRS274XCommand(), GERBER_DRAW_ITEM::SetLayerParameters(), StepAndRepeatItem(), and GERBVIEW_FRAME::UpdateTitleAndInfo().

216  {
217  return m_GBRLayerParams;
218  }
const wxArrayString& GERBER_FILE_IMAGE::GetMessages ( ) const
inline
COLOR4D GERBER_FILE_IMAGE::GetPositiveDrawColor ( ) const
inline

Definition at line 203 of file class_gerber_file_image.h.

References m_PositiveDrawColor.

Referenced by GBR_LAYOUT::Draw(), and GERBER_DRAW_ITEM::Draw().

203 { return m_PositiveDrawColor; }
bool GERBER_FILE_IMAGE::HasNegativeItems ( )

Function HasNegativeItems.

Returns
true if at least one item must be drawn in background color used to optimize screen refresh (when no items are in background color refresh can be faster)

Definition at line 221 of file class_gerber_file_image.cpp.

References GetItemsList(), m_GraphicLayer, m_hasNegativeItems, m_ImageNegative, and GERBER_DRAW_ITEM::Next().

Referenced by GBR_LAYOUT::Draw().

222 {
223  if( m_hasNegativeItems < 0 ) // negative items are not yet searched: find them if any
224  {
225  if( m_ImageNegative ) // A negative layer is expected having always negative objects.
226  m_hasNegativeItems = 1;
227  else
228  {
229  m_hasNegativeItems = 0;
230  for( GERBER_DRAW_ITEM* item = GetItemsList(); item; item = item->Next() )
231  {
232  if( item->GetLayer() != m_GraphicLayer )
233  continue;
234  if( item->HasNegativeItems() )
235  {
236  m_hasNegativeItems = 1;
237  break;
238  }
239  }
240  }
241  }
242  return m_hasNegativeItems == 1;
243 }
GERBER_DRAW_ITEM * Next() const
GERBER_DRAW_ITEM * GetItemsList()
Function GetItemsList.
void GERBER_FILE_IMAGE::InitToolTable ( )

Function InitToolTable.

Definition at line 260 of file class_gerber_file_image.cpp.

References D_CODE::Clear_D_CODE_Data(), FIRST_DCODE, m_Aperture_List, m_aperture_macros, D_CODE::m_Num_Dcode, and TOOLS_MAX_COUNT.

261 {
262  for( int count = 0; count < TOOLS_MAX_COUNT; count++ )
263  {
264  if( m_Aperture_List[count] == NULL )
265  continue;
266 
267  m_Aperture_List[count]->m_Num_Dcode = count + FIRST_DCODE;
269  }
270 
271  m_aperture_macros.clear();
272 }
APERTURE_MACRO_SET m_aperture_macros
a collection of APERTURE_MACROS, sorted by name
D_CODE * m_Aperture_List[TOOLS_MAX_COUNT]
Dcode (Aperture) List for this layer (max 999)
#define FIRST_DCODE
Definition: dcode.h:70
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:100
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
void Clear_D_CODE_Data()
Definition: dcode.cpp:78
bool GERBER_FILE_IMAGE::LoadGerberFile ( const wxString &  aFullFileName)

Read and load a gerber file.

Parameters
aFullFileName= the full filename of the Gerber file when the file cannot be loaded Warning and info messages are stored in m_messagesList
Returns
bool if OK, false if the gerber file was not loaded

Definition at line 86 of file readgerb.cpp.

References AddMessageToList(), ClearMessageList(), CMD_IDLE, DCodeNumber(), END_BLOCK, ENTER_RS274X_CMD, Execute_DCODE_Command(), Execute_G_Command(), GCodeNumber(), GERBER_BUFZ, m_CommandState, m_Current_File, m_CurrentPos, m_FileName, m_IJPos, m_InUse, m_Last_Pen_Command, ReadIJCoord(), ReadRS274XCommand(), ReadXYCoord(), ResetDefaultValues(), and StrPurge().

Referenced by GERBVIEW_FRAME::Read_GERBER_File().

87 {
88  int G_command = 0; // command number for G commands like G04
89  int D_commande = 0; // command number for D commands like D02
90  char line[GERBER_BUFZ];
91  char* text;
92 
95 
96  // Read the gerber file */
97  m_Current_File = wxFopen( aFullFileName, wxT( "rt" ) );
98 
99  if( m_Current_File == 0 )
100  return false;
101 
102  m_FileName = aFullFileName;
103 
104  LOCALE_IO toggleIo;
105 
106  wxString msg;
107 
108  while( true )
109  {
110  if( fgets( line, sizeof(line), m_Current_File ) == NULL )
111  break;
112 
113  text = StrPurge( line );
114 
115  while( text && *text )
116  {
117  switch( *text )
118  {
119  case ' ':
120  case '\r':
121  case '\n':
122  text++;
123  break;
124 
125  case '*': // End command
127  text++;
128  break;
129 
130  case 'M': // End file
132  while( *text )
133  text++;
134  break;
135 
136  case 'G': /* Line type Gxx : command */
137  G_command = GCodeNumber( text );
138  Execute_G_Command( text, G_command );
139  break;
140 
141  case 'D': /* Line type Dxx : Tool selection (xx > 0) or
142  * command if xx = 0..9 */
143  D_commande = DCodeNumber( text );
144  Execute_DCODE_Command( text, D_commande );
145  break;
146 
147  case 'X':
148  case 'Y': /* Move or draw command */
149  m_CurrentPos = ReadXYCoord( text );
150  if( *text == '*' ) // command like X12550Y19250*
151  {
152  Execute_DCODE_Command( text,
154  }
155  break;
156 
157  case 'I':
158  case 'J': /* Auxiliary Move command */
159  m_IJPos = ReadIJCoord( text );
160 
161  if( *text == '*' ) // command like X35142Y15945J504*
162  {
163  Execute_DCODE_Command( text,
165  }
166  break;
167 
168  case '%':
170  {
172  ReadRS274XCommand( line, text );
173  }
174  else //Error
175  {
176  AddMessageToList( wxT("Expected RS274X Command") );
178  text++;
179  }
180  break;
181 
182  default:
183  text++;
184  msg.Printf( wxT("Unexpected symbol <%c>"), *text );
185  AddMessageToList( msg );
186  break;
187  }
188  }
189  }
190 
191  fclose( m_Current_File );
192 
193  m_InUse = true;
194 
195  return true;
196 }
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
bool Execute_DCODE_Command(char *&text, int D_command)
Definition: rs274d.cpp:577
char * StrPurge(char *text)
Function StrPurge removes leading and training spaces, tabs and end of line chars in text return a po...
Definition: string.cpp:194
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
wxPoint ReadXYCoord(char *&Text)
Function ReadXYCoord Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm) ...
wxPoint ReadIJCoord(char *&Text)
Function ReadIJCoord Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm) These...
void ClearMessageList()
Function ClearMessageList Clear the message list Call it before reading a Gerber file.
int GCodeNumber(char *&Text)
Definition: rs274d.cpp:409
int DCodeNumber(char *&Text)
Definition: rs274d.cpp:432
bool Execute_G_Command(char *&text, int G_command)
Definition: rs274d.cpp:452
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
bool ReadRS274XCommand(char *aBuff, char *&text)
Function ReadRS274XCommand reads a single RS274X command terminated with a %.
Definition: rs274x.cpp:192
bool GERBER_FILE_IMAGE::ReadApertureMacro ( char *  aBuff,
char *&  text,
FILE *  gerber_file 
)

Function ReadApertureMacro reads in an aperture macro and saves it in m_aperture_macros.

Parameters
aBuffa character buffer at least GERBER_BUFZ long that can be used to read successive lines from the gerber file.
textA reference to a character pointer which gives the initial text to read from.
gerber_fileWhich file to read from for continuation.
Returns
bool - true if a macro was read in successfully, else false.

Definition at line 967 of file rs274x.cpp.

References AddMessageToList(), AMP_CIRCLE, AMP_COMMENT, AMP_EOF, AMP_LINE2, AMP_LINE20, AMP_LINE_CENTER, AMP_LINE_LOWER_LEFT, AMP_MOIRE, AMP_OUTLINE, AMP_POLYGON, AMP_THERMAL, AMP_UNKNOWN, FROM_UTF8(), GetChars(), GetNextLine(), m_aperture_macros, m_GerbMetric, APERTURE_MACRO::m_localparamStack, APERTURE_MACRO::name, AM_PRIMITIVE::params, AM_PRIMITIVE::primitive_id, APERTURE_MACRO::primitives, ReadInt(), and AM_PARAM::ReadParam().

Referenced by ExecuteRS274XCommand().

970 {
971  wxString msg;
972  APERTURE_MACRO am;
973 
974  // read macro name
975  while( *text )
976  {
977  if( *text == '*' )
978  {
979  ++text;
980  break;
981  }
982 
983  am.name.Append( *text++ );
984  }
985 
986  // Read aperture macro parameters
987  for( ; ; )
988  {
989  if( *text == '*' )
990  ++text;
991 
992  text = GetNextLine( buff, text, gerber_file );
993 
994  if( text == NULL ) // End of File
995  return false;
996 
997  // text points the beginning of a new line.
998 
999  // Test for the last line in aperture macro lis:
1000  // last line is % or *% sometime found.
1001  if( *text == '*' )
1002  ++text;
1003 
1004  if( *text == '%' )
1005  break; // exit with text still pointing at %
1006 
1007  int paramCount = 0; // will be set to the minimal parameters count,
1008  // depending on the actual primitive
1009  int primitive_type = AMP_UNKNOWN;
1010  // Test for a valid symbol at the beginning of a description:
1011  // it can be: a parameter declaration like $1=$2/4
1012  // or a digit (macro primitive selection)
1013  // all other symbols are illegal.
1014  if( *text == '$' ) // local parameter declaration, inside the aperture macro
1015  {
1016  am.m_localparamStack.push_back( AM_PARAM() );
1017  AM_PARAM& param = am.m_localparamStack.back();
1018  text = GetNextLine( buff, text, gerber_file );
1019  if( text == NULL) // End of File
1020  return false;
1021  param.ReadParam( text );
1022  continue;
1023  }
1024  else if( !isdigit(*text) ) // Ill. symbol
1025  {
1026  msg.Printf( wxT( "RS274X: Aperture Macro \"%s\": ill. symbol, line: \"%s\"" ),
1027  GetChars( am.name ), GetChars( FROM_UTF8( buff ) ) );
1028  AddMessageToList( msg );
1029  primitive_type = AMP_COMMENT;
1030  }
1031  else
1032  primitive_type = ReadInt( text );
1033 
1034  bool is_comment = false;
1035 
1036  switch( primitive_type )
1037  {
1038  case AMP_COMMENT: // lines starting by 0 are a comment
1039  paramCount = 0;
1040  is_comment = true;
1041  // Skip comment
1042  while( *text && ( *text != '*' ) )
1043  text++;
1044  break;
1045 
1046  case AMP_CIRCLE:
1047  paramCount = 4; // minimal count. can have a optional parameter (rotation)
1048  break;
1049 
1050  case AMP_LINE2:
1051  case AMP_LINE20:
1052  paramCount = 7;
1053  break;
1054 
1055  case AMP_LINE_CENTER:
1056  case AMP_LINE_LOWER_LEFT:
1057  paramCount = 6;
1058  break;
1059 
1060  case AMP_EOF:
1061  paramCount = 0;
1062  break;
1063 
1064  case AMP_OUTLINE:
1065  paramCount = 4;
1066  break;
1067 
1068  case AMP_POLYGON:
1069  paramCount = 6;
1070  break;
1071 
1072  case AMP_MOIRE:
1073  paramCount = 9;
1074  break;
1075 
1076  case AMP_THERMAL:
1077  paramCount = 6;
1078  break;
1079 
1080  default:
1081  // @todo, there needs to be a way of reporting the line number
1082  msg.Printf( wxT( "RS274X: Aperture Macro \"%s\": Invalid primitive id code %d, line: \"%s\"" ),
1083  GetChars( am.name ), primitive_type, GetChars( FROM_UTF8( buff ) ) );
1084  AddMessageToList( msg );
1085  return false;
1086  }
1087 
1088  if( is_comment )
1089  continue;
1090 
1091  AM_PRIMITIVE prim( m_GerbMetric );
1092  prim.primitive_id = (AM_PRIMITIVE_ID) primitive_type;
1093  int ii;
1094 
1095  for( ii = 0; ii < *text && *text != '*'; ++ii )
1096  {
1097  prim.params.push_back( AM_PARAM() );
1098 
1099  AM_PARAM& param = prim.params.back();
1100 
1101  text = GetNextLine( buff, text, gerber_file );
1102 
1103  if( text == NULL) // End of File
1104  return false;
1105 
1106  param.ReadParam( text );
1107  }
1108 
1109  if( ii < paramCount )
1110  {
1111  // maybe some day we can throw an exception and track a line number
1112  msg.Printf( wxT( "RS274X: read macro descr type %d: read %d parameters, insufficient parameters\n" ),
1113  prim.primitive_id, ii );
1114  AddMessageToList( msg );
1115 
1116  }
1117  // there are more parameters to read if this is an AMP_OUTLINE
1118  if( prim.primitive_id == AMP_OUTLINE )
1119  {
1120  // so far we have read [0]:exposure, [1]:#points, [2]:X start, [3]: Y start
1121  // Now read all the points, plus trailing rotation in degrees.
1122 
1123  // params[1] is a count of polygon points, so it must be given
1124  // in advance, i.e. be immediate.
1125  wxASSERT( prim.params[1].IsImmediate() );
1126 
1127  paramCount = (int) prim.params[1].GetValue( 0 ) * 2 + 1;
1128 
1129  for( int jj = 0; jj < paramCount && *text != '*'; ++jj )
1130  {
1131  prim.params.push_back( AM_PARAM() );
1132 
1133  AM_PARAM& param = prim.params.back();
1134 
1135  text = GetNextLine( buff, text, gerber_file );
1136 
1137  if( text == NULL ) // End of File
1138  return false;
1139 
1140  param.ReadParam( text );
1141  }
1142  }
1143 
1144  am.primitives.push_back( prim );
1145  }
1146 
1147  m_aperture_macros.insert( am );
1148 
1149  return true;
1150 }
APERTURE_MACRO_SET m_aperture_macros
a collection of APERTURE_MACROS, sorted by name
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
wxString name
The name of the aperture macro.
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
int ReadInt(char *&text, bool aSkipSeparator=true)
Function ReadInt reads an int from an ASCII character buffer.
static char * GetNextLine(char *aBuff, char *aText, FILE *aFile)
Function GetNextLine test for an end of line if an end of line is found: read a new line...
Definition: rs274x.cpp:941
AM_PRIMITIVE_ID
Enum AM_PRIMITIVE_ID is the set of all "aperture macro primitives" (primitive numbers).
bool ReadParam(char *&aText)
Function ReadParam Read one aperture macro parameter a parameter can be: a number a reference to an a...
Class AM_PARAM holds a parameter value for an "aperture macro" as defined within standard RS274X...
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
AM_PRIMITIVES primitives
A sequence of AM_PRIMITIVEs.
Struct AM_PRIMITIVE holds an aperture macro primitive as given in Table 3 of http://gerbv.sourceforge.net/docs/rs274xrevd_e.pdf.
Struct APERTURE_MACRO helps support the "aperture macro" defined within standard RS274X.
wxPoint GERBER_FILE_IMAGE::ReadIJCoord ( char *&  Text)

Function ReadIJCoord Returns the current coordinate type pointed to by InnJnn Text (InnnnJmmmm) These coordinates are relative, so if coordinate is absent, it's value defaults to 0.

Definition at line 172 of file rs274_read_XY_and_IJ_coordinates.cpp.

References IsNumber, KiROUND(), m_FmtLen, m_FmtScale, m_GerbMetric, m_IJPos, m_NoTrailingZeros, scale_list, wxPoint::x, and wxPoint::y.

Referenced by EXCELLON_IMAGE::LoadFile(), and LoadGerberFile().

173 {
174  wxPoint pos( 0, 0 );
175 
176  int type_coord = 0, current_coord, nbdigits;
177  bool is_float = false;
178  char* text;
179  char line[256];
180 
181  if( Text == NULL )
182  return pos;
183 
184  text = line;
185  while( *Text )
186  {
187  if( (*Text == 'I') || (*Text == 'J') )
188  {
189  type_coord = *Text;
190  Text++;
191  text = line;
192  nbdigits = 0;
193  while( IsNumber( *Text ) )
194  {
195  if( *Text == '.' )
196  is_float = true;
197 
198  // count digits only (sign and decimal point are not counted)
199  if( (*Text >= '0') && (*Text <='9') )
200  nbdigits++;
201 
202  *(text++) = *(Text++);
203  }
204 
205  *text = 0;
206  if( is_float )
207  {
208  // When X or Y values are float numbers, they are given in mm or inches
209  if( m_GerbMetric ) // units are mm
210  current_coord = KiROUND( atof( line ) * IU_PER_MILS / 0.0254 );
211  else // units are inches
212  current_coord = KiROUND( atof( line ) * IU_PER_MILS * 1000 );
213  }
214  else
215  {
216  int fmt_scale =
217  (type_coord == 'I') ? m_FmtScale.x : m_FmtScale.y;
218 
219  if( m_NoTrailingZeros )
220  {
221  int min_digit =
222  (type_coord == 'I') ? m_FmtLen.x : m_FmtLen.y;
223  while( nbdigits < min_digit )
224  {
225  *(text++) = '0';
226  nbdigits++;
227  }
228 
229  *text = 0;
230  }
231 
232  current_coord = atoi( line );
233 
234  double real_scale = scale_list[fmt_scale];
235 
236  if( m_GerbMetric )
237  real_scale = real_scale / 25.4;
238 
239  current_coord = KiROUND( current_coord * real_scale );
240  }
241  if( type_coord == 'I' )
242  pos.x = current_coord;
243  else if( type_coord == 'J' )
244  pos.y = current_coord;
245 
246  continue;
247  }
248  else
249  break;
250  }
251 
252  m_IJPos = pos;
253  return pos;
254 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
#define IsNumber(x)
static double scale_list[SCALE_LIST_SIZE]
bool GERBER_FILE_IMAGE::ReadRS274XCommand ( char *  aBuff,
char *&  text 
)

Function ReadRS274XCommand reads a single RS274X command terminated with a %.

Definition at line 192 of file rs274x.cpp.

References CMD_IDLE, ExecuteRS274XCommand(), GERBER_BUFZ, m_CommandState, m_Current_File, and ReadXCommand().

Referenced by LoadGerberFile().

193 {
194  bool ok = true;
195  int code_command;
196 
197  text++;
198 
199  for( ; ; )
200  {
201  while( *text )
202  {
203  switch( *text )
204  {
205  case '%': // end of command
206  text++;
208  goto exit; // success completion
209 
210  case ' ':
211  case '\r':
212  case '\n':
213  text++;
214  break;
215 
216  case '*':
217  text++;
218  break;
219 
220  default:
221  code_command = ReadXCommand( text );
222  ok = ExecuteRS274XCommand( code_command, buff, text );
223  if( !ok )
224  goto exit;
225  break;
226  }
227  }
228 
229  // end of current line, read another one.
230  if( fgets( buff, GERBER_BUFZ, m_Current_File ) == NULL )
231  {
232  // end of file
233  ok = false;
234  break;
235  }
236 
237  text = buff;
238  }
239 
240 exit:
241  return ok;
242 }
bool ExecuteRS274XCommand(int command, char *aBuff, char *&text)
Function ExecuteRS274XCommand executes 1 command.
Definition: rs274x.cpp:245
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
static int ReadXCommand(char *&text)
Function ReadXCommand reads in two bytes of data and assembles them into an int with the first byte i...
Definition: rs274x.cpp:123
wxPoint GERBER_FILE_IMAGE::ReadXYCoord ( char *&  Text)

Function ReadXYCoord Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm)

Definition at line 72 of file rs274_read_XY_and_IJ_coordinates.cpp.

References IsNumber, KiROUND(), m_CurrentPos, m_DecimalFormat, m_FmtLen, m_FmtScale, m_GerbMetric, m_NoTrailingZeros, m_Relative, scale_list, wxPoint::x, and wxPoint::y.

Referenced by EXCELLON_IMAGE::Execute_Drill_Command(), EXCELLON_IMAGE::Execute_EXCELLON_G_Command(), and LoadGerberFile().

73 {
74  wxPoint pos;
75  int type_coord = 0, current_coord, nbdigits;
76  bool is_float = m_DecimalFormat;
77  char* text;
78  char line[256];
79 
80 
81  if( m_Relative )
82  pos.x = pos.y = 0;
83  else
84  pos = m_CurrentPos;
85 
86  if( Text == NULL )
87  return pos;
88 
89  text = line;
90  while( *Text )
91  {
92  if( (*Text == 'X') || (*Text == 'Y') )
93  {
94  type_coord = *Text;
95  Text++;
96  text = line;
97  nbdigits = 0;
98 
99  while( IsNumber( *Text ) )
100  {
101  if( *Text == '.' ) // Force decimat format if reading a floating point number
102  is_float = true;
103 
104  // count digits only (sign and decimal point are not counted)
105  if( (*Text >= '0') && (*Text <='9') )
106  nbdigits++;
107  *(text++) = *(Text++);
108  }
109 
110  *text = 0;
111 
112  if( is_float )
113  {
114  // When X or Y values are float numbers, they are given in mm or inches
115  if( m_GerbMetric ) // units are mm
116  current_coord = KiROUND( atof( line ) * IU_PER_MILS / 0.0254 );
117  else // units are inches
118  current_coord = KiROUND( atof( line ) * IU_PER_MILS * 1000 );
119  }
120  else
121  {
122  int fmt_scale = (type_coord == 'X') ? m_FmtScale.x : m_FmtScale.y;
123 
124  if( m_NoTrailingZeros )
125  {
126  int min_digit =
127  (type_coord == 'X') ? m_FmtLen.x : m_FmtLen.y;
128  while( nbdigits < min_digit )
129  {
130  *(text++) = '0';
131  nbdigits++;
132  }
133 
134  *text = 0;
135  }
136 
137  current_coord = atoi( line );
138  double real_scale = scale_list[fmt_scale];
139 
140  if( m_GerbMetric )
141  real_scale = real_scale / 25.4;
142 
143  current_coord = KiROUND( current_coord * real_scale );
144  }
145 
146  if( type_coord == 'X' )
147  pos.x = current_coord;
148  else if( type_coord == 'Y' )
149  pos.y = current_coord;
150 
151  continue;
152  }
153  else
154  break;
155  }
156 
157  if( m_Relative )
158  {
159  pos.x += m_CurrentPos.x;
160  pos.y += m_CurrentPos.y;
161  }
162 
163  m_CurrentPos = pos;
164  return pos;
165 }
static int KiROUND(double v)
KiROUND rounds a floating point number to an int using "round halfway cases away from zero"...
Definition: common.h:107
#define IsNumber(x)
static double scale_list[SCALE_LIST_SIZE]
void GERBER_FILE_IMAGE::RemoveAttribute ( X2_ATTRIBUTE aAttribute)

Function RemoveAttribute.

Called when a TD command is found the Gerber file

Parameters
aAttributeis the X2_ATTRIBUTE which stores the full command Remove the attribute specified by the TD command. is no attribute, all current attributes specified by the TO and the TA commands are cleared. if a attribute name is specified (for instance TD.CN*%) is specified, only this attribute is cleared

Definition at line 359 of file class_gerber_file_image.cpp.

References GBR_NETLIST_METADATA::ClearAttribute(), X2_ATTRIBUTE::GetPrm(), m_AperFunction, and m_NetAttributeDict.

Referenced by ExecuteRS274XCommand().

360 {
361  /* Called when a %TD command is found
362  * Remove the attribute specified by the %TD command.
363  * is no attribute, all current attributes specified by the %TO and the %TA
364  * commands are cleared.
365  * if a attribute name is specified (for instance %TD.CN*%) is specified,
366  * only this attribute is cleared
367  */
368  m_NetAttributeDict.ClearAttribute( &aAttribute.GetPrm( 1 ) );
369 
370  if( aAttribute.GetPrm( 1 ).IsEmpty() || aAttribute.GetPrm( 1 ) == ".AperFunction" )
371  m_AperFunction.Clear();
372 }
const wxString & GetPrm(int aIdx)
GBR_NETLIST_METADATA m_NetAttributeDict
void ClearAttribute(const wxString *aName)
remove the net attribute specified by aName If aName == NULL or empty, remove all attributes ...
void GERBER_FILE_IMAGE::ResetDefaultValues ( )
virtual

Reimplemented in EXCELLON_IMAGE.

Definition at line 163 of file class_gerber_file_image.cpp.

References GERB_INTERPOL_LINEAR_1X, m_360Arc_enbl, m_CommandState, m_Current_File, m_Current_Tool, m_CurrentPos, m_DecimalFormat, m_Exposure, m_FileFunction, m_FileName, m_FmtLen, m_FmtScale, m_GBRLayerParams, m_GerbMetric, m_Has_DCode, m_hasNegativeItems, m_IJPos, m_ImageJustifyOffset, m_ImageJustifyXCenter, m_ImageJustifyYCenter, m_ImageName, m_ImageNegative, m_ImageOffset, m_ImageRotation, m_InUse, m_IsX2_file, m_Iterpolation, m_Last_Pen_Command, m_LocalRotation, m_MD5_value, m_MirrorA, m_MirrorB, m_NoTrailingZeros, m_Offset, m_PartString, m_PolygonFillMode, m_PolygonFillModeState, m_PreviousPos, m_Relative, m_Scale, m_Selected_Tool, m_SwapAxis, GERBER_LAYER::ResetDefaultValues(), wxPoint::x, and wxPoint::y.

Referenced by GERBER_FILE_IMAGE(), LoadGerberFile(), and EXCELLON_IMAGE::ResetDefaultValues().

164 {
165  m_InUse = false;
167  m_FileName.Empty();
168  m_ImageName = wxT( "no name" ); // Image name from the IN command
169  m_ImageNegative = false; // true = Negative image
170  m_IsX2_file = false; // true only if a %TF, %TA or %TD command
171  delete m_FileFunction; // file function parameters
172  m_FileFunction = NULL;
173  m_MD5_value.Empty(); // MD5 value found in a %TF.MD5 command
174  m_PartString.Empty(); // string found in a %TF.Part command
175  m_hasNegativeItems = -1; // set to uninitialized
176  m_ImageJustifyOffset = wxPoint(0,0); // Image justify Offset
177  m_ImageJustifyXCenter = false; // Image Justify Center on X axis (default = false)
178  m_ImageJustifyYCenter = false; // Image Justify Center on Y axis (default = false)
179  m_GerbMetric = false; // false = Inches (default), true = metric
180  m_Relative = false; // false = absolute Coord,
181  // true = relative Coord
182  m_NoTrailingZeros = false; // true: trailing zeros deleted
183  m_DecimalFormat = false; // true: use floating point notations for coordinates
184  m_ImageOffset.x = m_ImageOffset.y = 0; // Coord Offset, from IO command
185  m_ImageRotation = 0; // Allowed 0, 90, 180, 270 (in degree)
186  m_LocalRotation = 0.0; // Layer totation from RO command (in 0.1 degree)
187  m_Offset.x = 0;
188  m_Offset.y = 0; // Coord Offset, from OF command
189  m_Scale.x = m_Scale.y = 1.0; // scale (A and B) this layer
190  m_MirrorA = false; // true: miror / axe A (default = X)
191  m_MirrorB = false; // true: miror / axe B (default = Y)
192  m_SwapAxis = false; // false if A = X, B = Y; true if A =Y, B = Y
193  m_Has_DCode = false; // true = DCodes in file
194  // false = no DCode->
195  // search for separate DCode file
196  m_FmtScale.x = m_FmtScale.y = 4; // Initialize default format to 3.4 => 4
197  m_FmtLen.x = m_FmtLen.y = 3 + 4; // Initialize default format len = 3+4
198 
199  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Linear, 90 arc, Circ.
200  m_360Arc_enbl = false; // 360 deg circular
201  // interpolation disable
202  m_Current_Tool = 0; // Current Dcode selected
203  m_CommandState = 0; // State of the current command
204  m_CurrentPos.x = m_CurrentPos.y = 0; // current specified coord
205  m_PreviousPos.x = m_PreviousPos.y = 0; // last specified coord
206  m_IJPos.x = m_IJPos.y = 0; // current centre coord for
207  // plot arcs & circles
208  m_Current_File = NULL; // Gerber file to read
209  m_PolygonFillMode = false;
211  m_Selected_Tool = 0;
212  m_Last_Pen_Command = 0;
213  m_Exposure = false;
214 }
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
bool m_Exposure
whether an aperture macro tool is flashed on or off
void GERBER_FILE_IMAGE::StepAndRepeatItem ( const GERBER_DRAW_ITEM aItem)

Function StepAndRepeatItem Gerber format has a command Step an Repeat This function must be called when reading a gerber file and after creating a new gerber item that must be repeated (i.e when m_XRepeatCount or m_YRepeatCount are > 1)

Parameters
aItem= the item to repeat

Definition at line 283 of file class_gerber_file_image.cpp.

References DLIST< T >::Append(), GetLayerParams(), m_Drawings, GERBER_LAYER::m_XRepeatCount, GERBER_LAYER::m_YRepeatCount, GERBER_DRAW_ITEM::MoveXY(), scaletoIU(), wxPoint::x, and wxPoint::y.

Referenced by Execute_DCODE_Command(), EXCELLON_IMAGE::Execute_Drill_Command(), and Execute_G_Command().

284 {
285  if( GetLayerParams().m_XRepeatCount < 2 &&
286  GetLayerParams().m_YRepeatCount < 2 )
287  return; // Nothing to repeat
288 
289  // Duplicate item:
290  for( int ii = 0; ii < GetLayerParams().m_XRepeatCount; ii++ )
291  {
292  for( int jj = 0; jj < GetLayerParams().m_YRepeatCount; jj++ )
293  {
294  // the first gerber item already exists (this is the template)
295  // create duplicate only if ii or jj > 0
296  if( jj == 0 && ii == 0 )
297  continue;
298  GERBER_DRAW_ITEM* dupItem = new GERBER_DRAW_ITEM( aItem );
299  wxPoint move_vector;
300  move_vector.x = scaletoIU( ii * GetLayerParams().m_StepForRepeat.x,
301  GetLayerParams().m_StepForRepeatMetric );
302  move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y,
303  GetLayerParams().m_StepForRepeatMetric );
304  dupItem->MoveXY( move_vector );
305  m_Drawings.Append( dupItem );
306  }
307  }
308 }
void Append(T *aNewElement)
Function Append adds aNewElement to the end of the list.
Definition: dlist.h:177
int scaletoIU(double aCoord, bool isMetric)
Function scaletoIU converts a distance given in floating point to our internal units.
DLIST< GERBER_DRAW_ITEM > m_Drawings
void MoveXY(const wxPoint &aMoveVector)
Function MoveXY move this object.
GERBER_LAYER & GetLayerParams()
Function GetLayerParams.

Member Data Documentation

bool GERBER_FILE_IMAGE::m_360Arc_enbl
wxString GERBER_FILE_IMAGE::m_AperFunction

Definition at line 163 of file class_gerber_file_image.h.

Referenced by ExecuteRS274XCommand(), and RemoveAttribute().

D_CODE* GERBER_FILE_IMAGE::m_Aperture_List[TOOLS_MAX_COUNT]
private

Dcode (Aperture) List for this layer (max 999)

Definition at line 100 of file class_gerber_file_image.h.

Referenced by GERBER_FILE_IMAGE(), GetDCODE(), GetDcodesCount(), InitToolTable(), and ~GERBER_FILE_IMAGE().

APERTURE_MACRO_SET GERBER_FILE_IMAGE::m_aperture_macros

a collection of APERTURE_MACROS, sorted by name

Definition at line 159 of file class_gerber_file_image.h.

Referenced by FindApertureMacro(), InitToolTable(), and ReadApertureMacro().

int GERBER_FILE_IMAGE::m_CommandState
std::map<wxString, int> GERBER_FILE_IMAGE::m_ComponentsList
FILE* GERBER_FILE_IMAGE::m_Current_File
bool GERBER_FILE_IMAGE::m_DecimalFormat
bool GERBER_FILE_IMAGE::m_Exposure
private

whether an aperture macro tool is flashed on or off

Definition at line 101 of file class_gerber_file_image.h.

Referenced by Execute_DCODE_Command(), Execute_G_Command(), and ResetDefaultValues().

GERBER_LAYER GERBER_FILE_IMAGE::m_GBRLayerParams
private

Definition at line 103 of file class_gerber_file_image.h.

Referenced by GetLayerParams(), and ResetDefaultValues().

int GERBER_FILE_IMAGE::m_hasNegativeItems
private

Definition at line 171 of file class_gerber_file_image.h.

Referenced by HasNegativeItems(), and ResetDefaultValues().

bool GERBER_FILE_IMAGE::m_ImageJustifyXCenter
bool GERBER_FILE_IMAGE::m_ImageJustifyYCenter
wxString GERBER_FILE_IMAGE::m_ImageName
bool GERBER_FILE_IMAGE::m_InUse
bool GERBER_FILE_IMAGE::m_IsVisible
bool GERBER_FILE_IMAGE::m_IsX2_file
int GERBER_FILE_IMAGE::m_Last_Pen_Command
double GERBER_FILE_IMAGE::m_LocalRotation
wxString GERBER_FILE_IMAGE::m_MD5_value

Definition at line 118 of file class_gerber_file_image.h.

Referenced by ExecuteRS274XCommand(), and ResetDefaultValues().

wxArrayString GERBER_FILE_IMAGE::m_messagesList
private

Definition at line 170 of file class_gerber_file_image.h.

Referenced by GetMessages().

bool GERBER_FILE_IMAGE::m_MirrorA
bool GERBER_FILE_IMAGE::m_MirrorB
std::map<wxString, int> GERBER_FILE_IMAGE::m_NetnamesList
wxString GERBER_FILE_IMAGE::m_PartString

Definition at line 119 of file class_gerber_file_image.h.

Referenced by ExecuteRS274XCommand(), and ResetDefaultValues().

bool GERBER_FILE_IMAGE::m_PolygonFillMode
int GERBER_FILE_IMAGE::m_PolygonFillModeState
COLOR4D GERBER_FILE_IMAGE::m_PositiveDrawColor
wxPoint GERBER_FILE_IMAGE::m_PreviousPos
wxRealPoint GERBER_FILE_IMAGE::m_Scale
bool GERBER_FILE_IMAGE::m_SwapAxis

The documentation for this class was generated from the following files: