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
 
FILE * m_FilesList [INCLUDE_FILES_CNT_MAX+2]
 
int m_FilesPtr
 
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 236 of file class_gerber_file_image.h.

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

237  {
238  m_messagesList.Clear();
239  }
int GERBER_FILE_IMAGE::DCodeNumber ( char *&  Text)

Definition at line 436 of file rs274d.cpp.

References IsNumber.

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

437 {
438  int ii = 0;
439  char* text;
440  char line[1024];
441 
442  if( Text == NULL )
443  return 0;
444 
445  Text++;
446  text = line;
447  while( IsNumber( *Text ) )
448  *(text++) = *(Text++);
449 
450  *text = 0;
451  ii = atoi( line );
452  return ii;
453 }
#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 323 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().

324 {
325  wxString msg;
326 
327  aMainFrame->ClearMsgPanel();
328 
329  // Display Image name (Image specific)
330  aMainFrame->AppendMsgPanel( _( "Image name" ), m_ImageName, CYAN );
331 
332  // Display graphic layer number used to draw this Image
333  // (not a Gerber parameter but is also image specific)
334  msg.Printf( wxT( "%d" ), m_GraphicLayer + 1 );
335  aMainFrame->AppendMsgPanel( _( "Graphic layer" ), msg, BROWN );
336 
337  // Display Image rotation (Image specific)
338  msg.Printf( wxT( "%d" ), m_ImageRotation );
339  aMainFrame->AppendMsgPanel( _( "Img Rot." ), msg, CYAN );
340 
341  // Display Image polarity (Image specific)
342  msg = m_ImageNegative ? _("Negative") : _("Normal");
343  aMainFrame->AppendMsgPanel( _( "Polarity" ), msg, BROWN );
344 
345  // Display Image justification and offset for justification (Image specific)
346  msg = m_ImageJustifyXCenter ? _("Center") : _("Normal");
347  aMainFrame->AppendMsgPanel( _( "X Justify" ), msg, DARKRED );
348 
349  msg = m_ImageJustifyYCenter ? _("Center") : _("Normal");
350  aMainFrame->AppendMsgPanel( _( "Y Justify" ), msg, DARKRED );
351 
352  if( g_UserUnit == INCHES )
353  msg.Printf( wxT( "X=%f Y=%f" ), Iu2Mils( m_ImageJustifyOffset.x ) / 1000.0,
354  Iu2Mils( m_ImageJustifyOffset.y ) / 1000.0 );
355  else
356  msg.Printf( wxT( "X=%f Y=%f" ), Iu2Millimeter( m_ImageJustifyOffset.x ),
357  Iu2Millimeter( m_ImageJustifyOffset.y ) );
358 
359  aMainFrame->AppendMsgPanel( _( "Image Justify Offset" ), msg, DARKRED );
360 }
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:731
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:742
Definition: colors.h:62
bool GERBER_FILE_IMAGE::Execute_DCODE_Command ( char *&  text,
int  D_command 
)

Definition at line 581 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().

582 {
583  wxSize size( 15, 15 );
584 
585  APERTURE_T aperture = APT_CIRCLE;
586  GERBER_DRAW_ITEM* gbritem;
587 
588  int dcode = 0;
589  D_CODE* tool = NULL;
590  wxString msg;
591 
592  if( D_commande >= FIRST_DCODE ) // This is a "Set tool" command
593  {
594  if( D_commande > (TOOLS_MAX_COUNT - 1) )
595  D_commande = TOOLS_MAX_COUNT - 1;
596 
597  // remember which tool is selected, nothing is done with it in this
598  // call
599  m_Current_Tool = D_commande;
600 
601  D_CODE* pt_Dcode = GetDCODE( D_commande, false );
602  if( pt_Dcode )
603  pt_Dcode->m_InUse = true;
604 
605  return true;
606  }
607  else // D_commande = 0..9: this is a pen command (usually D1, D2 or D3)
608  {
609  m_Last_Pen_Command = D_commande;
610  }
611 
612  if( m_PolygonFillMode ) // Enter a polygon description:
613  {
614  switch( D_commande )
615  {
616  case 1: // code D01 Draw line, exposure ON
617  if( !m_Exposure ) // Start a new polygon outline:
618  {
619  m_Exposure = true;
620  gbritem = new GERBER_DRAW_ITEM( this );
621  m_Drawings.Append( gbritem );
622  gbritem->m_Shape = GBR_POLYGON;
623  gbritem->m_Flashed = false;
624  }
625 
626  switch( m_Iterpolation )
627  {
630  gbritem = m_Drawings.GetLast();
631 
632  fillArcPOLY( gbritem, m_PreviousPos,
634  ( m_Iterpolation == GERB_INTERPOL_ARC_NEG ) ? false : true,
635  m_360Arc_enbl, GetLayerParams().m_LayerNegative );
636  break;
637 
638  default:
639  gbritem = m_Drawings.GetLast();
640 
641  gbritem->m_Start = m_PreviousPos; // m_Start is used as temporary storage
642  if( gbritem->m_PolyCorners.size() == 0 )
643  gbritem->m_PolyCorners.push_back( gbritem->m_Start );
644 
645  gbritem->m_End = m_CurrentPos; // m_End is used as temporary storage
646  gbritem->m_PolyCorners.push_back( gbritem->m_End );
647  break;
648  }
649 
652  break;
653 
654  case 2: // code D2: exposure OFF (i.e. "move to")
655  if( m_Exposure && GetItemsList() ) // End of polygon
656  {
657  gbritem = m_Drawings.GetLast();
658  StepAndRepeatItem( *gbritem );
659  }
660  m_Exposure = false;
663  break;
664 
665  default:
666  return false;
667  }
668  }
669  else
670  {
671  switch( D_commande )
672  {
673  case 1: // code D01 Draw line, exposure ON
674  m_Exposure = true;
675 
676  tool = GetDCODE( m_Current_Tool, false );
677  if( tool )
678  {
679  size = tool->m_Size;
680  dcode = tool->m_Num_Dcode;
681  aperture = tool->m_Shape;
682  }
683 
684  switch( m_Iterpolation )
685  {
687  gbritem = new GERBER_DRAW_ITEM( this );
688  m_Drawings.Append( gbritem );
689 
690  fillLineGBRITEM( gbritem, dcode, m_PreviousPos,
691  m_CurrentPos, size, GetLayerParams().m_LayerNegative );
692  StepAndRepeatItem( *gbritem );
693  break;
694 
698  wxBell();
699  break;
700 
703  gbritem = new GERBER_DRAW_ITEM( this );
704  m_Drawings.Append( gbritem );
705 
706  fillArcGBRITEM( gbritem, dcode, m_PreviousPos,
707  m_CurrentPos, m_IJPos, size,
709  false : true, m_360Arc_enbl, GetLayerParams().m_LayerNegative );
710  StepAndRepeatItem( *gbritem );
711  break;
712 
713  default:
714  msg.Printf( wxT( "RS274D: DCODE Command: interpol error (type %X)" ),
715  m_Iterpolation );
716  AddMessageToList( msg );
717  break;
718  }
719 
721  break;
722 
723  case 2: // code D2: exposure OFF (i.e. "move to")
724  m_Exposure = false;
726  break;
727 
728  case 3: // code D3: flash aperture
729  tool = GetDCODE( m_Current_Tool, false );
730  if( tool )
731  {
732  size = tool->m_Size;
733  dcode = tool->m_Num_Dcode;
734  aperture = tool->m_Shape;
735  }
736 
737  gbritem = new GERBER_DRAW_ITEM( this );
738  m_Drawings.Append( gbritem );
739  fillFlashedGBRITEM( gbritem, aperture, dcode, m_CurrentPos,
740  size, GetLayerParams().m_LayerNegative );
741  StepAndRepeatItem( *gbritem );
743  break;
744 
745  default:
746  return false;
747  }
748  }
749 
750  return true;
751 }
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:339
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:161
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:108
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:212
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 456 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().

457 {
458 // D( printf( "%22s: G_CODE<%d>\n", __func__, G_command ); )
459 
460  switch( G_command )
461  {
462  case GC_PHOTO_MODE: // can starts a D03 flash command: redundant, can
463  // be safely ignored
464  break;
465 
468  break;
469 
472  break;
473 
476  break;
477 
478  case GC_COMMENT:
479  // Skip comment, but only if the line does not start by "G04 #@! TF"
480  // which is a metadata
481  if( strncmp( text, " #@! TF", 7 ) == 0 )
482  {
483  text += 7;
485  dummy.ParseAttribCmd( m_Current_File, NULL, 0, text );
486  if( dummy.IsFileFunction() )
487  {
488  delete m_FileFunction;
490  }
491  }
492 
493  while ( *text && (*text != '*') )
494  text++;
495  break;
496 
499  break;
500 
503  break;
504 
507  break;
508 
509  case GC_SELECT_TOOL:
510  {
511  int D_commande = DCodeNumber( text );
512  if( D_commande < FIRST_DCODE )
513  return false;
514  if( D_commande > (TOOLS_MAX_COUNT - 1) )
515  D_commande = TOOLS_MAX_COUNT - 1;
516  m_Current_Tool = D_commande;
517  D_CODE* pt_Dcode = GetDCODE( D_commande, false );
518  if( pt_Dcode )
519  pt_Dcode->m_InUse = true;
520  break;
521  }
522 
523  case GC_SPECIFY_INCHES:
524  m_GerbMetric = false; // false = Inches, true = metric
525  break;
526 
528  m_GerbMetric = true; // false = Inches, true = metric
529  break;
530 
531  case GC_TURN_OFF_360_INTERPOL: // disable Multi cadran arc and Arc interpol
532  m_360Arc_enbl = false;
533  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // not sure it should be done
534  break;
535 
537  m_360Arc_enbl = true;
538  break;
539 
541  m_Relative = false; // false = absolute Coord, true = relative
542  // Coord
543  break;
544 
546  m_Relative = true; // false = absolute Coord, true = relative
547  // Coord
548  break;
549 
551  m_PolygonFillMode = true;
552  m_Exposure = false;
553  break;
554 
556  if( m_Exposure && GetItemsList() ) // End of polygon
557  {
558  GERBER_DRAW_ITEM * gbritem = m_Drawings.GetLast();
559  StepAndRepeatItem( *gbritem );
560  }
561  m_Exposure = false;
562  m_PolygonFillMode = false;
564  break;
565 
566  case GC_MOVE: // Non existent
567  default:
568  {
569  wxString msg;
570  msg.Printf( wxT( "G%0.2d command not handled" ), G_command );
571  AddMessageToList( msg );
572  return false;
573  }
574  }
575 
576 
577  return true;
578 }
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:436
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, INCLUDE_FILE, INCLUDE_FILES_CNT_MAX, 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_FilesList, m_FilesPtr, 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(), PLOTTER_FILM, 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  char line[GERBER_BUFZ];
252  wxString msg;
253  double fcoord;
254  bool x_fmt_known = false;
255  bool y_fmt_known = false;
256 
257  // conv_scale = scaling factor from inch to Internal Unit
258  double conv_scale = IU_PER_MILS * 1000;
259  if( m_GerbMetric )
260  conv_scale /= 25.4;
261 
262 // DBG( printf( "%22s: Command <%c%c>\n", __func__, (command >> 8) & 0xFF, command & 0xFF ); )
263 
264  switch( command )
265  {
266  case FORMAT_STATEMENT:
267  seq_len = 2;
268 
269  while( *text != '*' )
270  {
271  switch( *text )
272  {
273  case ' ':
274  text++;
275  break;
276 
277  case 'L': // No Leading 0
278  m_DecimalFormat = false;
279  m_NoTrailingZeros = false;
280  text++;
281  break;
282 
283  case 'T': // No trailing 0
284  m_DecimalFormat = false;
285  m_NoTrailingZeros = true;
286  text++;
287  break;
288 
289  case 'A': // Absolute coord
290  m_Relative = false;
291  text++;
292  break;
293 
294  case 'I': // Relative coord
295  m_Relative = true;
296  text++;
297  break;
298 
299  case 'G':
300  case 'N': // Sequence code (followed by one digit: the sequence len)
301  // (sometimes found before the X,Y sequence)
302  // Obscure option
303  text++;
304  seq_char = *text++;
305  if( (seq_char >= '0') && (seq_char <= '9') )
306  seq_len = seq_char - '0';
307  break;
308 
309  case 'D':
310  case 'M': // Sequence code (followed by one digit: the sequence len)
311  // (sometimes found after the X,Y sequence)
312  // Obscure option
313  code = *text++;
314  if( ( *text >= '0' ) && ( *text<= '9' ) )
315  text++; // skip the digit
316  else if( code == 'D' )
317  // Decimal format: sometimes found, but not really documented
318  m_DecimalFormat = true;
319  break;
320 
321  case 'X':
322  case 'Y':
323  {
324  code = *(text++);
325  char ctmp = *(text++) - '0';
326  if( code == 'X' )
327  {
328  x_fmt_known = true;
329  // number of digits after the decimal point (0 to 7 allowed)
330  m_FmtScale.x = *text - '0';
331  m_FmtLen.x = ctmp + m_FmtScale.x;
332 
333  // m_FmtScale is 0 to 7
334  // (Old Gerber specification was 0 to 6)
335  if( m_FmtScale.x < 0 )
336  m_FmtScale.x = 0;
337  if( m_FmtScale.x > 7 )
338  m_FmtScale.x = 7;
339  }
340  else
341  {
342  y_fmt_known = true;
343  m_FmtScale.y = *text - '0';
344  m_FmtLen.y = ctmp + m_FmtScale.y;
345  if( m_FmtScale.y < 0 )
346  m_FmtScale.y = 0;
347  if( m_FmtScale.y > 7 )
348  m_FmtScale.y = 7;
349  }
350  text++;
351  }
352  break;
353 
354  case '*':
355  break;
356 
357  default:
358  msg.Printf( wxT( "Unknown id (%c) in FS command" ),
359  *text );
360  AddMessageToList( msg );
361  GetEndOfBlock( buff, text, m_Current_File );
362  ok = false;
363  break;
364  }
365  }
366  if( !x_fmt_known || !y_fmt_known )
367  AddMessageToList( wxT( "RS274X: Format Statement (FS) without X or Y format" ) );
368 
369  break;
370 
371  case AXIS_SELECT: // command ASAXBY*% or %ASAYBX*%
372  m_SwapAxis = false;
373  if( strncasecmp( text, "AYBX", 4 ) == 0 )
374  m_SwapAxis = true;
375  break;
376 
377  case MIRROR_IMAGE: // command %MIA0B0*%, %MIA0B1*%, %MIA1B0*%, %MIA1B1*%
378  m_MirrorA = m_MirrorB = 0;
379  while( *text && *text != '*' )
380  {
381  switch( *text )
382  {
383  case 'A': // Mirror A axis ?
384  text++;
385  if( *text == '1' )
386  m_MirrorA = true;
387  break;
388 
389  case 'B': // Mirror B axis ?
390  text++;
391  if( *text == '1' )
392  m_MirrorB = true;
393  break;
394 
395  default:
396  text++;
397  break;
398  }
399  }
400  break;
401 
402  case MODE_OF_UNITS:
403  code = ReadXCommand( text );
404  if( code == INCH )
405  m_GerbMetric = false;
406  else if( code == MILLIMETER )
407  m_GerbMetric = true;
408  conv_scale = m_GerbMetric ? IU_PER_MILS / 25.4 : IU_PER_MILS;
409  break;
410 
411  case FILE_ATTRIBUTE: // Command %TF ...
412  m_IsX2_file = true;
413  {
415  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
416 
417  if( dummy.IsFileFunction() )
418  {
419  delete m_FileFunction;
421  }
422  else if( dummy.IsFileMD5() )
423  {
424  m_MD5_value = dummy.GetPrm( 1 );
425  }
426  else if( dummy.IsFilePart() )
427  {
428  m_PartString = dummy.GetPrm( 1 );
429  }
430  }
431  break;
432 
433  case APERTURE_ATTRIBUTE: // Command %TA ... Not yet supported
434  {
436  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
437 
438  if( dummy.GetAttribute() == ".AperFunction" )
439  {
440  m_AperFunction = dummy.GetPrm( 1 );
441 
442  // A few function values can have other parameters. Add them
443  for( int ii = 2; ii < dummy.GetPrmCount(); ii++ )
444  m_AperFunction << "," << dummy.GetPrm( ii );
445  }
446  }
447  break;
448 
449  case NET_ATTRIBUTE: // Command %TO currently %TO.P %TO.N and %TO.C
450  {
452 
453  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
454 
455  if( dummy.GetAttribute() == ".N" )
456  {
459  }
460  else if( dummy.GetAttribute() == ".C" )
461  {
464  }
465  else if( dummy.GetAttribute() == ".P" )
466  {
470  }
471  }
472  break;
473 
474  case REMOVE_APERTURE_ATTRIBUTE: // Command %TD ...
475  {
477  dummy.ParseAttribCmd( m_Current_File, buff, GERBER_BUFZ, text );
478  RemoveAttribute( dummy );
479  }
480  break;
481 
482  case OFFSET: // command: OFAnnBnn (nn = float number) = layer Offset
483  m_Offset.x = m_Offset.y = 0;
484  while( *text != '*' )
485  {
486  switch( *text )
487  {
488  case 'A': // A axis offset in current unit (inch or mm)
489  text++;
490  fcoord = ReadDouble( text );
491  m_Offset.x = KiROUND( fcoord * conv_scale );
492  break;
493 
494  case 'B': // B axis offset in current unit (inch or mm)
495  text++;
496  fcoord = ReadDouble( text );
497  m_Offset.y = KiROUND( fcoord * conv_scale );
498  break;
499  }
500  }
501  break;
502 
503  case SCALE_FACTOR:
504  m_Scale.x = m_Scale.y = 1.0;
505  while( *text != '*' )
506  {
507  switch( *text )
508  {
509  case 'A': // A axis scale
510  text++;
511  m_Scale.x = ReadDouble( text );
512  break;
513 
514  case 'B': // B axis scale
515  text++;
516  m_Scale.y = ReadDouble( text );
517  break;
518  }
519  }
520  break;
521 
522  case IMAGE_OFFSET: // command: IOAnnBnn (nn = float number) = Image Offset
524  while( *text != '*' )
525  {
526  switch( *text )
527  {
528  case 'A': // A axis offset in current unit (inch or mm)
529  text++;
530  fcoord = ReadDouble( text );
531  m_ImageOffset.x = KiROUND( fcoord * conv_scale );
532  break;
533 
534  case 'B': // B axis offset in current unit (inch or mm)
535  text++;
536  fcoord = ReadDouble( text );
537  m_ImageOffset.y = KiROUND( fcoord * conv_scale );
538  break;
539  }
540  }
541  break;
542 
543  case IMAGE_ROTATION: // command IR0* or IR90* or IR180* or IR270*
544  if( strncasecmp( text, "0*", 2 ) == 0 )
545  m_ImageRotation = 0;
546  else if( strncasecmp( text, "90*", 3 ) == 0 )
547  m_ImageRotation = 90;
548  else if( strncasecmp( text, "180*", 4 ) == 0 )
549  m_ImageRotation = 180;
550  else if( strncasecmp( text, "270*", 4 ) == 0 )
551  m_ImageRotation = 270;
552  else
553  AddMessageToList( _( "RS274X: Command \"IR\" rotation value not allowed" ) );
554  break;
555 
556  case STEP_AND_REPEAT: // command SR, like %SRX3Y2I5.0J2*%
557  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
559  GetLayerParams().m_StepForRepeat.x = 0.0; // offset for Step and Repeat command
561  GetLayerParams().m_YRepeatCount = 1; // The repeat count
562  GetLayerParams().m_StepForRepeatMetric = m_GerbMetric; // the step units
563  while( *text && *text != '*' )
564  {
565  switch( *text )
566  {
567  case 'I': // X axis offset
568  text++;
570  break;
571 
572  case 'J': // Y axis offset
573  text++;
575  break;
576 
577  case 'X': // X axis repeat count
578  text++;
580  break;
581 
582  case 'Y': // Y axis offset
583  text++;
585  break;
586  default:
587  text++;
588  break;
589  }
590  }
591  break;
592 
593  case IMAGE_JUSTIFY: // Command IJAnBn*
594  m_ImageJustifyXCenter = false; // Image Justify Center on X axis (default = false)
595  m_ImageJustifyYCenter = false; // Image Justify Center on Y axis (default = false)
596  m_ImageJustifyOffset = wxPoint(0,0); // Image Justify Offset on XY axis (default = 0,0)
597  while( *text && *text != '*' )
598  {
599  // IJ command is (for A or B axis) AC or AL or A<coordinate>
600  switch( *text )
601  {
602  case 'A': // A axis justify
603  text++;
604  if( *text == 'C' )
605  {
606  m_ImageJustifyXCenter = true;
607  text++;
608  }
609  else if( *text == 'L' )
610  {
611  m_ImageJustifyXCenter = true;
612  text++;
613  }
614  else m_ImageJustifyOffset.x = KiROUND( ReadDouble( text ) * conv_scale);
615  break;
616 
617  case 'B': // B axis justify
618  text++;
619  if( *text == 'C' )
620  {
621  m_ImageJustifyYCenter = true;
622  text++;
623  }
624  else if( *text == 'L' )
625  {
626  m_ImageJustifyYCenter = true;
627  text++;
628  }
629  else m_ImageJustifyOffset.y = KiROUND( ReadDouble( text ) * conv_scale);
630  break;
631  default:
632  text++;
633  break;
634  }
635  }
640  break;
641 
642  case KNOCKOUT:
643  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
644  msg = _( "RS274X: Command KNOCKOUT ignored by GerbView" ) ;
645  AddMessageToList( msg );
646  break;
647 
648  case PLOTTER_FILM: // Command PF <string>
649  // This is an info about film that must be used to plot this file
650  // Has no meaning here. We just display this string
651  msg = wxT( "Plotter Film info:<br>" );
652  while( *text != '*' )
653  {
654  msg.Append( *text++ );
655  }
656  AddMessageToList( msg );
657  break;
658 
659  case ROTATE: // Layer rotation: command like %RO45*%
660  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
661  m_LocalRotation =ReadDouble( text ); // Store layer rotation in degrees
662  break;
663 
664  case IMAGE_NAME:
665  m_ImageName.Empty();
666  while( *text != '*' )
667  {
668  m_ImageName.Append( *text++ );
669  }
670 
671  break;
672 
673  case LAYER_NAME:
674  m_Iterpolation = GERB_INTERPOL_LINEAR_1X; // Start a new Gerber layer
675  GetLayerParams( ).m_LayerName.Empty();
676  while( *text != '*' )
677  {
678  GetLayerParams( ).m_LayerName.Append( *text++ );
679  }
680 
681  break;
682 
683  case IMAGE_POLARITY:
684  if( strncasecmp( text, "NEG", 3 ) == 0 )
685  m_ImageNegative = true;
686  else
687  m_ImageNegative = false;
688  DBG( printf( "%22s: IMAGE_POLARITY m_ImageNegative=%s\n", __func__,
689  m_ImageNegative ? "true" : "false" ); )
690  break;
691 
692  case LAYER_POLARITY:
693  if( *text == 'C' )
695 
696  else
698 
699 // DBG( printf( "%22s: LAYER_POLARITY m_LayerNegative=%s\n", __func__,
700 // GetLayerParams().m_LayerNegative ? "true" : "false" ); )
701  break;
702 
703  case INCLUDE_FILE:
705  {
706  ok = false;
707  AddMessageToList( _( "Too many include files!!" ) );
708  break;
709  }
710 
711  strncpy( line, text, sizeof(line)-1 );
712  line[sizeof(line)-1] = '\0';
713 
714  strtok( line, "*%%\n\r" );
716 
717  m_Current_File = fopen( line, "rt" );
718  if( m_Current_File == 0 )
719  {
720  msg.Printf( wxT( "include file <%s> not found." ), line );
721  AddMessageToList( msg );
722  ok = false;
724  break;
725  }
726  m_FilesPtr++;
727  break;
728 
729  case AP_MACRO: // lines like %AMMYMACRO*
730  // 5,1,8,0,0,1.08239X$1,22.5*
731  // %
732  /*ok = */ReadApertureMacro( buff, text, m_Current_File );
733  break;
734 
735  case AP_DEFINITION:
736 
737  /* input example: %ADD30R,0.081800X0.101500*%
738  * Aperture definition has 4 options: C, R, O, P
739  * (Circle, Rect, Oval, regular Polygon)
740  * and shapes can have a hole (round or rectangular).
741  * All optional parameters values start by X
742  * at this point, text points to 2nd 'D'
743  */
744  if( *text++ != 'D' )
745  {
746  ok = false;
747  break;
748  }
749 
750  m_Has_DCode = true;
751 
752  code = ReadInt( text );
753 
754  D_CODE* dcode;
755  dcode = GetDCODE( code );
756 
757  if( dcode == NULL )
758  break;
759 
761 
762  // at this point, text points to character after the ADD<num>,
763  // i.e. R in example above. If text[0] is one of the usual
764  // apertures: (C,R,O,P), there is a comma after it.
765  if( text[1] == ',' )
766  {
767  char stdAperture = *text;
768 
769  text += 2; // skip "C," for example
770 
771  dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale );
772  dcode->m_Size.y = dcode->m_Size.x;
773 
774  switch( stdAperture ) // Aperture desceiption has optional parameters. Read them
775  {
776  case 'C': // Circle
777  dcode->m_Shape = APT_CIRCLE;
778  while( *text == ' ' )
779  text++;
780 
781  if( *text == 'X' )
782  {
783  text++;
784  dcode->m_Drill.x = dcode->m_Drill.y =
785  KiROUND( ReadDouble( text ) * conv_scale );
787  }
788 
789  while( *text == ' ' )
790  text++;
791 
792  if( *text == 'X' )
793  {
794  text++;
795  dcode->m_Drill.y =
796  KiROUND( ReadDouble( text ) * conv_scale );
797 
799  }
800  dcode->m_Defined = true;
801  break;
802 
803  case 'O': // oval
804  case 'R': // rect
805  dcode->m_Shape = (stdAperture == 'O') ? APT_OVAL : APT_RECT;
806 
807  while( *text == ' ' )
808  text++;
809 
810  if( *text == 'X' )
811  {
812  text++;
813  dcode->m_Size.y =
814  KiROUND( ReadDouble( text ) * conv_scale );
815  }
816 
817  while( *text == ' ' )
818  text++;
819 
820  if( *text == 'X' )
821  {
822  text++;
823  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
824  dcode->m_Drill.y = dcode->m_Drill.x;
826  }
827 
828  while( *text == ' ' )
829  text++;
830 
831  if( *text == 'X' )
832  {
833  text++;
834  dcode->m_Drill.y =
835  KiROUND( ReadDouble( text ) * conv_scale );
837  }
838  dcode->m_Defined = true;
839  break;
840 
841  case 'P':
842 
843  /* Regular polygon: a command line like %ADD12P,0.040X10X25X0.025X0.025X0.0150*%
844  * params are: <diameter>, X<edge count>, X<Rotation>, X<X hole dim>, X<Y hole dim>
845  */
846  dcode->m_Shape = APT_POLYGON;
847  while( *text == ' ' )
848  text++;
849 
850  if( *text == 'X' )
851  {
852  text++;
853  dcode->m_EdgesCount = ReadInt( text );
854  }
855 
856  while( *text == ' ' )
857  text++;
858 
859  if( *text == 'X' )
860  {
861  text++;
862  dcode->m_Rotation = ReadDouble( text );
863  }
864 
865  while( *text == ' ' )
866  text++;
867 
868  if( *text == 'X' )
869  {
870  text++;
871  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
872  dcode->m_Drill.y = dcode->m_Drill.x =
874  }
875 
876  while( *text == ' ' )
877  text++;
878 
879  if( *text == 'X' )
880  {
881  text++;
882  dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale );
884  }
885  dcode->m_Defined = true;
886  break;
887  }
888  }
889  else // text[0] starts an aperture macro name
890  {
891  APERTURE_MACRO am_lookup;
892 
893  while( *text && *text != '*' && *text != ',' )
894  am_lookup.name.Append( *text++ );
895 
896  // When an aperture definition is like %AMLINE2* 22,1,$1,$2,0,0,-45*
897  // the ADDxx<MACRO_NAME> command has parameters, like %ADD14LINE2,0.8X0.5*%
898  if( *text == ',' )
899  { // Read aperture macro parameters and store them
900  text++; // text points the first parameter
901  while( *text && *text != '*' )
902  {
903  double param = ReadDouble( text );
904  dcode->AppendParam( param );
905  while( isspace( *text ) ) text++;
906  if( *text == 'X' )
907  ++text;
908  }
909  }
910 
911  // lookup the aperture macro here.
912  APERTURE_MACRO* pam = FindApertureMacro( am_lookup );
913  if( !pam )
914  {
915  msg.Printf( wxT( "RS274X: aperture macro %s not found\n" ),
916  TO_UTF8( am_lookup.name ) );
917  AddMessageToList( msg );
918  ok = false;
919  break;
920  }
921 
922  dcode->m_Shape = APT_MACRO;
923  dcode->SetMacro( pam );
924  }
925  break;
926 
927  default:
928  ok = false;
929  break;
930  }
931 
932  (void) seq_len; // quiet g++, or delete the unused variable.
933 
934  ok = GetEndOfBlock( buff, text, m_Current_File );
935 
936  return ok;
937 }
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
#define INCLUDE_FILES_CNT_MAX
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:1002
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:940
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 are just copied...
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:127
GERBER_LAYER & GetLayerParams()
Function GetLayerParams.
int m_NetAttribType
the type of net info (used to define the gerber string to create)
FILE * m_FilesList[INCLUDE_FILES_CNT_MAX+2]
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 413 of file rs274d.cpp.

References IsNumber.

Referenced by LoadGerberFile().

414 {
415  int ii = 0;
416  char* text;
417  char line[1024];
418 
419  if( Text == NULL )
420  return 0;
421  Text++;
422  text = line;
423  while( IsNumber( *Text ) )
424  {
425  *(text++) = *(Text++);
426  }
427 
428  *text = 0;
429  ii = atoi( line );
430  return ii;
431 }
#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 249 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().

250 {
251  int count = 0;
252 
253  for( unsigned ii = 0; ii < DIM( m_Aperture_List ); ii++ )
254  {
255  if( m_Aperture_List[ii] )
256  if( m_Aperture_List[ii]->m_InUse || m_Aperture_List[ii]->m_Defined )
257  ++count;
258  }
259 
260  return count;
261 }
#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_DRAW_ITEM * GERBER_FILE_IMAGE::GetItemsList ( )
GERBER_LAYER& GERBER_FILE_IMAGE::GetLayerParams ( )
inline

Function GetLayerParams.

Returns
the current layers params

Definition at line 218 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().

219  {
220  return m_GBRLayerParams;
221  }
const wxArrayString& GERBER_FILE_IMAGE::GetMessages ( ) const
inline
COLOR4D GERBER_FILE_IMAGE::GetPositiveDrawColor ( ) const
inline

Definition at line 206 of file class_gerber_file_image.h.

References m_PositiveDrawColor.

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

206 { 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 225 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().

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

Function InitToolTable.

Definition at line 264 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.

265 {
266  for( int count = 0; count < TOOLS_MAX_COUNT; count++ )
267  {
268  if( m_Aperture_List[count] == NULL )
269  continue;
270 
271  m_Aperture_List[count]->m_Num_Dcode = count + FIRST_DCODE;
273  }
274 
275  m_aperture_macros.clear();
276 }
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_FilesList, m_FilesPtr, 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  wxString path = wxPathOnly( aFullFileName );
105 
106  // This change is needed to load included files, if exists:
107  if( path != wxEmptyString )
108  wxSetWorkingDirectory( path );
109 
110  LOCALE_IO toggleIo;
111 
112  wxString msg;
113 
114  while( true )
115  {
116  if( fgets( line, sizeof(line), m_Current_File ) == NULL )
117  {
118  if( m_FilesPtr == 0 )
119  break;
120 
121  fclose( m_Current_File );
122 
123  m_FilesPtr--;
125 
126  continue;
127  }
128 
129  text = StrPurge( line );
130 
131  while( text && *text )
132  {
133  switch( *text )
134  {
135  case ' ':
136  case '\r':
137  case '\n':
138  text++;
139  break;
140 
141  case '*': // End command
143  text++;
144  break;
145 
146  case 'M': // End file
148  while( *text )
149  text++;
150  break;
151 
152  case 'G': /* Line type Gxx : command */
153  G_command = GCodeNumber( text );
154  Execute_G_Command( text, G_command );
155  break;
156 
157  case 'D': /* Line type Dxx : Tool selection (xx > 0) or
158  * command if xx = 0..9 */
159  D_commande = DCodeNumber( text );
160  Execute_DCODE_Command( text, D_commande );
161  break;
162 
163  case 'X':
164  case 'Y': /* Move or draw command */
165  m_CurrentPos = ReadXYCoord( text );
166  if( *text == '*' ) // command like X12550Y19250*
167  {
168  Execute_DCODE_Command( text,
170  }
171  break;
172 
173  case 'I':
174  case 'J': /* Auxiliary Move command */
175  m_IJPos = ReadIJCoord( text );
176  if( *text == '*' ) // command like X35142Y15945J504*
177  {
178  Execute_DCODE_Command( text,
180  }
181  break;
182 
183  case '%':
185  {
187  ReadRS274XCommand( line, text );
188  }
189  else //Error
190  {
191  AddMessageToList( wxT("Expected RS274X Command") );
193  text++;
194  }
195  break;
196 
197  default:
198  text++;
199  msg.Printf( wxT("Unexpected symbol <%c>"), *text );
200  AddMessageToList( msg );
201  break;
202  }
203  }
204  }
205 
206  fclose( m_Current_File );
207 
208  m_InUse = true;
209 
210  return true;
211 }
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:581
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:413
int DCodeNumber(char *&Text)
Definition: rs274d.cpp:436
bool Execute_G_Command(char *&text, int G_command)
Definition: rs274d.cpp:456
#define GERBER_BUFZ
size of single line of a text from a gerber file.
Definition: gerbview.h:39
FILE * m_FilesList[INCLUDE_FILES_CNT_MAX+2]
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 1002 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().

1005 {
1006  wxString msg;
1007  APERTURE_MACRO am;
1008 
1009  // read macro name
1010  while( *text )
1011  {
1012  if( *text == '*' )
1013  {
1014  ++text;
1015  break;
1016  }
1017 
1018  am.name.Append( *text++ );
1019  }
1020 
1021  // Read aperture macro parameters
1022  for( ; ; )
1023  {
1024  if( *text == '*' )
1025  ++text;
1026 
1027  text = GetNextLine( buff, text, gerber_file ); // Get next line
1028  if( text == NULL ) // End of File
1029  return false;
1030 
1031  // text points the beginning of a new line.
1032 
1033  // Test for the last line in aperture macro lis:
1034  // last line is % or *% sometime found.
1035  if( *text == '*' )
1036  ++text;
1037  if( *text == '%' )
1038  break; // exit with text still pointing at %
1039 
1040  int paramCount = 0;
1041  int primitive_type = AMP_UNKNOWN;
1042  // Test for a valid symbol at the beginning of a description:
1043  // it can be: a parameter declaration like $1=$2/4
1044  // or a digit (macro primitive selection)
1045  // all other symbols are illegal.
1046  if( *text == '$' ) // local parameter declaration, inside the aperture macro
1047  {
1048  am.m_localparamStack.push_back( AM_PARAM() );
1049  AM_PARAM& param = am.m_localparamStack.back();
1050  text = GetNextLine( buff, text, gerber_file );
1051  if( text == NULL) // End of File
1052  return false;
1053  param.ReadParam( text );
1054  continue;
1055  }
1056  else if( !isdigit(*text) ) // Ill. symbol
1057  {
1058  msg.Printf( wxT( "RS274X: Aperture Macro \"%s\": ill. symbol, line: \"%s\"" ),
1059  GetChars( am.name ), GetChars( FROM_UTF8( buff ) ) );
1060  AddMessageToList( msg );
1061  primitive_type = AMP_COMMENT;
1062  }
1063  else
1064  primitive_type = ReadInt( text );
1065 
1066  switch( primitive_type )
1067  {
1068  case AMP_COMMENT: // lines starting by 0 are a comment
1069  paramCount = 0;
1070  // Skip comment
1071  while( *text && (*text != '*') )
1072  text++;
1073  break;
1074 
1075  case AMP_CIRCLE:
1076  paramCount = 4;
1077  break;
1078 
1079  case AMP_LINE2:
1080  case AMP_LINE20:
1081  paramCount = 7;
1082  break;
1083 
1084  case AMP_LINE_CENTER:
1085  case AMP_LINE_LOWER_LEFT:
1086  paramCount = 6;
1087  break;
1088 
1089  case AMP_EOF:
1090  paramCount = 0;
1091  break;
1092 
1093  case AMP_OUTLINE:
1094  paramCount = 4;
1095  break;
1096 
1097  case AMP_POLYGON:
1098  paramCount = 6;
1099  break;
1100 
1101  case AMP_MOIRE:
1102  paramCount = 9;
1103  break;
1104 
1105  case AMP_THERMAL:
1106  paramCount = 6;
1107  break;
1108 
1109  default:
1110  // @todo, there needs to be a way of reporting the line number
1111  msg.Printf( wxT( "RS274X: Aperture Macro \"%s\": Invalid primitive id code %d, line: \"%s\"" ),
1112  GetChars( am.name ), primitive_type, GetChars( FROM_UTF8( buff ) ) );
1113  AddMessageToList( msg );
1114  return false;
1115  }
1116 
1117  AM_PRIMITIVE prim( m_GerbMetric );
1118  prim.primitive_id = (AM_PRIMITIVE_ID) primitive_type;
1119  int ii;
1120 
1121  for( ii = 0; ii < paramCount && *text && *text != '*'; ++ii )
1122  {
1123  prim.params.push_back( AM_PARAM() );
1124 
1125  AM_PARAM& param = prim.params.back();
1126 
1127  text = GetNextLine( buff, text, gerber_file );
1128 
1129  if( text == NULL) // End of File
1130  return false;
1131 
1132  param.ReadParam( text );
1133  }
1134 
1135  if( ii < paramCount )
1136  {
1137  // maybe some day we can throw an exception and track a line number
1138  msg.Printf( wxT( "RS274X: read macro descr type %d: read %d parameters, insufficient parameters\n" ),
1139  prim.primitive_id, ii );
1140  AddMessageToList( msg );
1141 
1142  }
1143  // there are more parameters to read if this is an AMP_OUTLINE
1144  if( prim.primitive_id == AMP_OUTLINE )
1145  {
1146  // so far we have read [0]:exposure, [1]:#points, [2]:X start, [3]: Y start
1147  // Now read all the points, plus trailing rotation in degrees.
1148 
1149  // params[1] is a count of polygon points, so it must be given
1150  // in advance, i.e. be immediate.
1151  wxASSERT( prim.params[1].IsImmediate() );
1152 
1153  paramCount = (int) prim.params[1].GetValue( 0 ) * 2 + 1;
1154 
1155  for( int jj = 0; jj < paramCount && *text != '*'; ++jj )
1156  {
1157  prim.params.push_back( AM_PARAM() );
1158 
1159  AM_PARAM& param = prim.params.back();
1160 
1161  text = GetNextLine( buff, text, gerber_file );
1162 
1163  if( text == NULL ) // End of File
1164  return false;
1165 
1166  param.ReadParam( text );
1167  }
1168  }
1169 
1170  am.primitives.push_back( prim );
1171  }
1172 
1173  m_aperture_macros.insert( am );
1174 
1175  return true;
1176 }
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:976
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:127
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 363 of file class_gerber_file_image.cpp.

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

Referenced by ExecuteRS274XCommand().

364 {
365  /* Called when a %TD command is found
366  * Remove the attribute specified by the %TD command.
367  * is no attribute, all current attributes specified by the %TO and the %TA
368  * commands are cleared.
369  * if a attribute name is specified (for instance %TD.CN*%) is specified,
370  * only this attribute is cleared
371  */
372  m_NetAttributeDict.ClearAttribute( &aAttribute.GetPrm( 1 ) );
373 
374  if( aAttribute.GetPrm( 1 ).IsEmpty() || aAttribute.GetPrm( 1 ) == ".AperFunction" )
375  m_AperFunction.Clear();
376 }
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 DIM, 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_FilesList, m_FilesPtr, 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_FilesPtr = 0;
210  m_PolygonFillMode = false;
212  m_Selected_Tool = 0;
213  m_Last_Pen_Command = 0;
214  m_Exposure = false;
215 
216  for( unsigned ii = 0; ii < DIM( m_FilesList ); ii++ )
217  m_FilesList[ii] = NULL;
218 }
#define DIM(x)
of elements in an array
Definition: macros.h:98
X2_ATTRIBUTE_FILEFUNCTION * m_FileFunction
bool m_Exposure
whether an aperture macro tool is flashed on or off
FILE * m_FilesList[INCLUDE_FILES_CNT_MAX+2]
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 287 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().

288 {
289  if( GetLayerParams().m_XRepeatCount < 2 &&
290  GetLayerParams().m_YRepeatCount < 2 )
291  return; // Nothing to repeat
292 
293  // Duplicate item:
294  for( int ii = 0; ii < GetLayerParams().m_XRepeatCount; ii++ )
295  {
296  for( int jj = 0; jj < GetLayerParams().m_YRepeatCount; jj++ )
297  {
298  // the first gerber item already exists (this is the template)
299  // create duplicate only if ii or jj > 0
300  if( jj == 0 && ii == 0 )
301  continue;
302  GERBER_DRAW_ITEM* dupItem = new GERBER_DRAW_ITEM( aItem );
303  wxPoint move_vector;
304  move_vector.x = scaletoIU( ii * GetLayerParams().m_StepForRepeat.x,
305  GetLayerParams().m_StepForRepeatMetric );
306  move_vector.y = scaletoIU( jj * GetLayerParams().m_StepForRepeat.y,
307  GetLayerParams().m_StepForRepeatMetric );
308  dupItem->MoveXY( move_vector );
309  m_Drawings.Append( dupItem );
310  }
311  }
312 }
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 166 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 162 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().

FILE* GERBER_FILE_IMAGE::m_FilesList[INCLUDE_FILES_CNT_MAX+2]
int GERBER_FILE_IMAGE::m_FilesPtr
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 174 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 173 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: