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 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 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: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 249 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().

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

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

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

Referenced by LoadGerberFile().

197 {
198  bool ok = true;
199  int code_command;
200 
201  text++;
202 
203  for( ; ; )
204  {
205  while( *text )
206  {
207  switch( *text )
208  {
209  case '%': // end of command
210  text++;
212  goto exit; // success completion
213 
214  case ' ':
215  case '\r':
216  case '\n':
217  text++;
218  break;
219 
220  case '*':
221  text++;
222  break;
223 
224  default:
225  code_command = ReadXCommand( text );
226  ok = ExecuteRS274XCommand( code_command, buff, text );
227  if( !ok )
228  goto exit;
229  break;
230  }
231  }
232 
233  // end of current line, read another one.
234  if( fgets( buff, GERBER_BUFZ, m_Current_File ) == NULL )
235  {
236  // end of file
237  ok = false;
238  break;
239  }
240 
241  text = buff;
242  }
243 
244 exit:
245  return ok;
246 }
bool ExecuteRS274XCommand(int command, char *aBuff, char *&text)
Function ExecuteRS274XCommand executes 1 command.
Definition: rs274x.cpp:249
#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: