KiCad PCB EDA Suite
EXCELLON_IMAGE Class Reference

#include <class_excellon.h>

Inheritance diagram for EXCELLON_IMAGE:
GERBER_FILE_IMAGE

Public Member Functions

 EXCELLON_IMAGE (int layer)
 
 ~EXCELLON_IMAGE ()
 
virtual void ResetDefaultValues () override
 
bool LoadFile (const wxString &aFullFileName)
 Read and load a drill (EXCELLON format) file. More...
 
void Clear_GERBER_FILE_IMAGE ()
 
bool LoadGerberFile (const wxString &aFullFileName)
 Read and load a gerber file. More...
 
const wxArrayString & GetMessages () const
 
int GetDcodesCount ()
 
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 Types

enum  excellon_state { READ_HEADER_STATE, READ_PROGRAM_STATE }
 

Private Member Functions

bool Execute_HEADER_Command (char *&text)
 
bool Select_Tool (char *&text)
 
bool Execute_EXCELLON_G_Command (char *&text)
 
bool Execute_Drill_Command (char *&text)
 
bool readToolInformation (char *&aText)
 Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list. More...
 
int TCodeNumber (char *&aText)
 
void SelectUnits (bool aMetric)
 

Private Attributes

excellon_state m_State
 
bool m_SlotOn
 

Detailed Description

Definition at line 89 of file class_excellon.h.

Member Enumeration Documentation

Enumerator
READ_HEADER_STATE 
READ_PROGRAM_STATE 

Definition at line 92 of file class_excellon.h.

92  {
93  READ_HEADER_STATE, // When we are in this state, we are reading header
94  READ_PROGRAM_STATE // When we are in this state, we are reading drill data
95  };

Constructor & Destructor Documentation

EXCELLON_IMAGE::EXCELLON_IMAGE ( int  layer)
inline

Definition at line 100 of file class_excellon.h.

References READ_HEADER_STATE.

100  : EXCELLON_IMAGE( int layer ) :
101  GERBER_FILE_IMAGE( layer )
102  {
104  m_SlotOn = false;
105  }
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
EXCELLON_IMAGE(int layer)
excellon_state m_State
EXCELLON_IMAGE::~EXCELLON_IMAGE ( )
inline

Definition at line 108 of file class_excellon.h.

108 {};

Member Function Documentation

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

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 LoadFile(), and GERBER_FILE_IMAGE::LoadGerberFile().

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

Definition at line 436 of file rs274d.cpp.

References IsNumber.

Referenced by GERBER_FILE_IMAGE::Execute_G_Command(), GERBER_FILE_IMAGE::LoadGerberFile(), and 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)
inherited

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, GERBER_FILE_IMAGE::m_GraphicLayer, GERBER_FILE_IMAGE::m_ImageJustifyOffset, GERBER_FILE_IMAGE::m_ImageJustifyXCenter, GERBER_FILE_IMAGE::m_ImageJustifyYCenter, GERBER_FILE_IMAGE::m_ImageName, GERBER_FILE_IMAGE::m_ImageNegative, GERBER_FILE_IMAGE::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:734
void ClearMsgPanel(void)
Clear all messages from the message panel.
Definition: draw_frame.cpp:745
Definition: colors.h:62
bool GERBER_FILE_IMAGE::Execute_DCODE_Command ( char *&  text,
int  D_command 
)
inherited

Definition at line 581 of file rs274d.cpp.

References GERBER_FILE_IMAGE::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, GERBER_FILE_IMAGE::GetDCODE(), GERBER_FILE_IMAGE::GetItemsList(), DLIST< T >::GetLast(), GERBER_FILE_IMAGE::GetLayerParams(), GERBER_FILE_IMAGE::m_360Arc_enbl, GERBER_FILE_IMAGE::m_Current_Tool, GERBER_FILE_IMAGE::m_CurrentPos, GERBER_FILE_IMAGE::m_Drawings, GERBER_DRAW_ITEM::m_End, GERBER_FILE_IMAGE::m_Exposure, GERBER_DRAW_ITEM::m_Flashed, GERBER_FILE_IMAGE::m_IJPos, D_CODE::m_InUse, GERBER_FILE_IMAGE::m_Iterpolation, GERBER_FILE_IMAGE::m_Last_Pen_Command, D_CODE::m_Num_Dcode, GERBER_DRAW_ITEM::m_PolyCorners, GERBER_FILE_IMAGE::m_PolygonFillMode, GERBER_FILE_IMAGE::m_PolygonFillModeState, GERBER_FILE_IMAGE::m_PreviousPos, GERBER_DRAW_ITEM::m_Shape, D_CODE::m_Shape, D_CODE::m_Size, GERBER_DRAW_ITEM::m_Start, GERBER_FILE_IMAGE::StepAndRepeatItem(), and TOOLS_MAX_COUNT.

Referenced by GERBER_FILE_IMAGE::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 EXCELLON_IMAGE::Execute_Drill_Command ( char *&  text)
private

Definition at line 515 of file excellon_read_drill_file.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), DLIST< T >::Append(), Execute_EXCELLON_G_Command(), fillFlashedGBRITEM(), fillLineGBRITEM(), GERBER_FILE_IMAGE::GetDCODE(), GERBER_FILE_IMAGE::m_Current_Tool, GERBER_FILE_IMAGE::m_CurrentPos, GERBER_FILE_IMAGE::m_Drawings, D_CODE::m_Num_Dcode, GERBER_FILE_IMAGE::m_PreviousPos, D_CODE::m_Shape, D_CODE::m_Size, m_SlotOn, GERBER_FILE_IMAGE::ReadXYCoord(), and GERBER_FILE_IMAGE::StepAndRepeatItem().

Referenced by LoadFile().

516 {
517  D_CODE* tool;
518  GERBER_DRAW_ITEM * gbritem;
519 
520  while( true )
521  {
522  switch( *text )
523  {
524  case 'X':
525  ReadXYCoord( text );
526  break;
527  case 'Y':
528  ReadXYCoord( text );
529  break;
530  case 'G': // G85 is found here for oval holes
533  break;
534  case 0: // E.O.L: execute command
535  tool = GetDCODE( m_Current_Tool, false );
536 
537  if( !tool )
538  {
539  wxString msg;
540  msg.Printf( _( "Tool %d not defined" ), m_Current_Tool );
541  AddMessageToList( msg );
542  return false;
543  }
544 
545  gbritem = new GERBER_DRAW_ITEM( this );
546  m_Drawings.Append( gbritem );
547 
548  if( m_SlotOn ) // Oblong hole
549  {
550  fillLineGBRITEM( gbritem, tool->m_Num_Dcode,
552  tool->m_Size, false );
553  // the hole is made: reset the slot on command (G85)
554  // (it is needed for each oblong hole)
555  m_SlotOn = false;
556  }
557  else
558  {
559  fillFlashedGBRITEM( gbritem, tool->m_Shape, tool->m_Num_Dcode,
560  m_CurrentPos, tool->m_Size, false );
561  }
562 
563  StepAndRepeatItem( *gbritem );
565  return true;
566  break;
567 
568  default:
569  text++;
570  break;
571  }
572  }
573 
574  return true;
575 }
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
wxPoint ReadXYCoord(char *&Text)
Function ReadXYCoord Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm) ...
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:98
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
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 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
int m_Num_Dcode
D code value ( >= 10 )
Definition: dcode.h:100
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
DLIST< GERBER_DRAW_ITEM > m_Drawings
bool Execute_EXCELLON_G_Command(char *&text)
void StepAndRepeatItem(const GERBER_DRAW_ITEM &aItem)
Function StepAndRepeatItem Gerber format has a command Step an Repeat This function must be called wh...
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
bool EXCELLON_IMAGE::Execute_EXCELLON_G_Command ( char *&  text)
private

Definition at line 616 of file excellon_read_drill_file.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), DRILL_G_ABSOLUTE, DRILL_G_CCWMOVE, DRILL_G_CWMOVE, DRILL_G_DRILL, DRILL_G_INCREMENTAL, DRILL_G_LINEARMOVE, DRILL_G_ROUT, DRILL_G_SLOT, DRILL_G_UNKNOWN, DRILL_G_ZERO_SET, FROM_UTF8(), GERB_INTERPOL_ARC_NEG, GERB_INTERPOL_ARC_POS, GERB_INTERPOL_LINEAR_1X, GetChars(), EXCELLON_CMD::m_Code, GERBER_FILE_IMAGE::m_CurrentPos, GERBER_FILE_IMAGE::m_Iterpolation, EXCELLON_CMD::m_Name, GERBER_FILE_IMAGE::m_Offset, GERBER_FILE_IMAGE::m_PolygonFillMode, GERBER_FILE_IMAGE::m_Relative, m_SlotOn, and GERBER_FILE_IMAGE::ReadXYCoord().

Referenced by Execute_Drill_Command(), and LoadFile().

617 {
618  EXCELLON_CMD* cmd = NULL;
619  bool success = false;
620  int id = DRILL_G_UNKNOWN;
621 
622  // Search command in list
623  EXCELLON_CMD* candidate;
624  char * gcmd = text; // gcmd points the G command, for error messages.
625 
626  for( unsigned ii = 0; ; ii++ )
627  {
628  candidate = &excellon_G_CmdList[ii];
629  int len = candidate->m_Name.size();
630  if( len == 0 ) // End of list reached
631  break;
632  if( candidate->m_Name.compare( 0, len, text, len ) == 0 ) // found.
633  {
634  cmd = candidate;
635  text += len;
636  success = true;
637  id = cmd->m_Code;
638  break;
639  }
640  }
641 
642  switch( id )
643  {
644  case DRILL_G_ZERO_SET:
645  ReadXYCoord( text );
647  break;
648 
649  case DRILL_G_ROUT:
650  m_SlotOn = false;
651  m_PolygonFillMode = true;
652  break;
653 
654  case DRILL_G_DRILL:
655  m_SlotOn = false;
656  m_PolygonFillMode = false;
657  break;
658 
659  case DRILL_G_SLOT:
660  m_SlotOn = true;
661  break;
662 
663  case DRILL_G_LINEARMOVE:
665  break;
666 
667  case DRILL_G_CWMOVE:
669  break;
670 
671  case DRILL_G_CCWMOVE:
673  break;
674 
675  case DRILL_G_ABSOLUTE:
676  m_Relative = false; // false = absolute coord
677  break;
678 
679  case DRILL_G_INCREMENTAL:
680  m_Relative = true; // true = relative coord
681  break;
682 
683  case DRILL_G_UNKNOWN:
684  default:
685  {
686  wxString msg;
687  msg.Printf( _( "Unknown Excellon G Code: &lt;%s&gt;" ), GetChars(FROM_UTF8(gcmd)) );
688  AddMessageToList( msg );
689  while( *text )
690  text++;
691  return false;
692  }
693  }
694  return success;
695 }
static EXCELLON_CMD excellon_G_CmdList[]
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
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
wxPoint ReadXYCoord(char *&Text)
Function ReadXYCoord Returns the current coordinate type pointed to by XnnYnn Text (XnnnnYmmmm) ...
std::string m_Name
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
bool GERBER_FILE_IMAGE::Execute_G_Command ( char *&  text,
int  G_command 
)
inherited

Definition at line 456 of file rs274d.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), GERBER_FILE_IMAGE::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, GERBER_FILE_IMAGE::GetDCODE(), GERBER_FILE_IMAGE::GetItemsList(), DLIST< T >::GetLast(), X2_ATTRIBUTE::IsFileFunction(), GERBER_FILE_IMAGE::m_360Arc_enbl, GERBER_FILE_IMAGE::m_Current_File, GERBER_FILE_IMAGE::m_Current_Tool, GERBER_FILE_IMAGE::m_Drawings, GERBER_FILE_IMAGE::m_Exposure, GERBER_FILE_IMAGE::m_FileFunction, GERBER_FILE_IMAGE::m_GerbMetric, D_CODE::m_InUse, GERBER_FILE_IMAGE::m_Iterpolation, GERBER_FILE_IMAGE::m_PolygonFillMode, GERBER_FILE_IMAGE::m_PolygonFillModeState, GERBER_FILE_IMAGE::m_Relative, X2_ATTRIBUTE::ParseAttribCmd(), GERBER_FILE_IMAGE::StepAndRepeatItem(), and TOOLS_MAX_COUNT.

Referenced by GERBER_FILE_IMAGE::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 EXCELLON_IMAGE::Execute_HEADER_Command ( char *&  text)
private

Definition at line 302 of file excellon_read_drill_file.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), DRILL_AUTOMATIC_SPEED, DRILL_AUTOMATIC_TOOL_CHANGE, DRILL_AXIS_VERSION, DRILL_DETECT_BROKEN, DRILL_FMT, DRILL_IMPERIALHEADER, DRILL_INCREMENTALHEADER, DRILL_M_BEGINPATTERN, DRILL_M_CANNEDTEXT, DRILL_M_END, DRILL_M_ENDHEADER, DRILL_M_ENDPATTERN, DRILL_M_ENDREWIND, DRILL_M_HEADER, DRILL_M_IMPERIAL, DRILL_M_LONGMESSAGE, DRILL_M_MESSAGE, DRILL_M_METRIC, DRILL_M_TIPCHECK, DRILL_M_UNKNOWN, DRILL_METRICHEADER, DRILL_RESET_CMD, DRILL_REWIND_STOP, DRILL_SKIP, DRILL_TOOL_CHANGE_STOP, DRILL_TOOL_INFORMATION, EXCELLON_CMD::m_Code, EXCELLON_CMD::m_Name, GERBER_FILE_IMAGE::m_NoTrailingZeros, GERBER_FILE_IMAGE::m_Relative, m_State, READ_HEADER_STATE, READ_PROGRAM_STATE, readToolInformation(), and SelectUnits().

Referenced by LoadFile().

303 {
304  EXCELLON_CMD* cmd = NULL;
305  wxString msg;
306 
307  // Search command in list
308  for( unsigned ii = 0; ; ii++ )
309  {
310  EXCELLON_CMD* candidate = &excellonHeaderCmdList[ii];
311  int len = candidate->m_Name.size();
312 
313  if( len == 0 ) // End of list reached
314  break;
315 
316  if( candidate->m_Name.compare( 0, len, text, len ) == 0 ) // found.
317  {
318  cmd = candidate;
319  text += len;
320  break;
321  }
322  }
323 
324  if( !cmd )
325  {
326  msg.Printf( wxT( "Unknown Excellon command &lt;%s&gt;" ), text );
327  AddMessageToList( msg );
328  while( *text )
329  text++;
330 
331  return false;
332  }
333 
334  // Execute command
335  // some do nothing
336  switch( cmd->m_Code )
337  {
338  case DRILL_SKIP:
339  case DRILL_M_UNKNOWN:
340  break;
341 
342  case DRILL_M_END:
343  break;
344 
345  case DRILL_M_ENDREWIND:
346  break;
347 
348  case DRILL_M_MESSAGE:
349  break;
350 
351  case DRILL_M_LONGMESSAGE:
352  break;
353 
354  case DRILL_M_HEADER:
356  break;
357 
358  case DRILL_M_ENDHEADER:
360  break;
361 
362  case DRILL_REWIND_STOP: // End of header. No action in a viewer
364  break;
365 
366  case DRILL_M_METRIC:
367  SelectUnits( true );
368  break;
369 
370  case DRILL_METRICHEADER: // command like METRIC,TZ or METRIC,LZ
371  SelectUnits( true );
372  if( *text != ',' )
373  {
374  AddMessageToList( _( "METRIC command has no parameter" ) );
375  break;
376  }
377  text++; // skip separator
378  if( *text == 'T' )
379  m_NoTrailingZeros = false;
380  else
381  m_NoTrailingZeros = true;
382  break;
383 
384  case DRILL_M_IMPERIAL:
385  SelectUnits( false );
386  break;
387 
388  case DRILL_IMPERIALHEADER: // command like INCH,TZ or INCH,LZ
389  SelectUnits( false );
390  if( *text != ',' )
391  {
392  AddMessageToList( _( "INCH command has no parameter" ) );
393  break;
394  }
395  text++; // skip separator
396  if( *text == 'T' )
397  m_NoTrailingZeros = false;
398  else
399  m_NoTrailingZeros = true;
400  break;
401 
403  break;
404 
405  case DRILL_M_ENDPATTERN:
406  break;
407 
408  case DRILL_M_CANNEDTEXT:
409  break;
410 
411  case DRILL_M_TIPCHECK:
412  break;
413 
414  case DRILL_DETECT_BROKEN:
415  break;
416 
418  if( *text != ',' )
419  {
420  AddMessageToList( _( "ICI command has no parameter" ) );
421  break;
422  }
423  text++; // skip separator
424  // Parameter should be ON or OFF
425  if( strncasecmp( text, "OFF", 3 ) == 0 )
426  m_Relative = false;
427  else if( strncasecmp( text, "ON", 2 ) == 0 )
428  m_Relative = true;
429  else
430  AddMessageToList( _( "ICI command has incorrect parameter" ) );
431  break;
432 
434  break;
435 
437  break;
438 
439  case DRILL_AXIS_VERSION:
440  break;
441 
442  case DRILL_RESET_CMD:
443  break;
444 
446  break;
447 
448  case DRILL_FMT:
449  break;
450 
452  readToolInformation( text );
453  break;
454  }
455 
456  while( *text )
457  text++;
458 
459  return true;
460 }
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
static EXCELLON_CMD excellonHeaderCmdList[]
std::string m_Name
excellon_state m_State
bool readToolInformation(char *&aText)
Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list...
void SelectUnits(bool aMetric)
bool GERBER_FILE_IMAGE::ExecuteRS274XCommand ( int  command,
char *  aBuff,
char *&  text 
)
inherited

Function ExecuteRS274XCommand executes 1 command.

Definition at line 245 of file rs274x.cpp.

References GERBER_FILE_IMAGE::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, GERBER_FILE_IMAGE::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(), GERBER_FILE_IMAGE::GetDCODE(), GetEndOfBlock(), GERBER_FILE_IMAGE::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, GERBER_FILE_IMAGE::m_AperFunction, GBR_NETLIST_METADATA::m_Cmpref, GERBER_FILE_IMAGE::m_Current_File, GERBER_FILE_IMAGE::m_DecimalFormat, D_CODE::m_Defined, D_CODE::m_Drill, D_CODE::m_DrillShape, D_CODE::m_EdgesCount, GERBER_FILE_IMAGE::m_FileFunction, GERBER_FILE_IMAGE::m_FilesList, GERBER_FILE_IMAGE::m_FilesPtr, GERBER_FILE_IMAGE::m_FmtLen, GERBER_FILE_IMAGE::m_FmtScale, GERBER_FILE_IMAGE::m_GerbMetric, GERBER_FILE_IMAGE::m_Has_DCode, GERBER_FILE_IMAGE::m_ImageJustifyOffset, GERBER_FILE_IMAGE::m_ImageJustifyXCenter, GERBER_FILE_IMAGE::m_ImageJustifyYCenter, GERBER_FILE_IMAGE::m_ImageName, GERBER_FILE_IMAGE::m_ImageNegative, GERBER_FILE_IMAGE::m_ImageOffset, GERBER_FILE_IMAGE::m_ImageRotation, GERBER_FILE_IMAGE::m_IsX2_file, GERBER_FILE_IMAGE::m_Iterpolation, GERBER_LAYER::m_LayerName, GERBER_LAYER::m_LayerNegative, GERBER_FILE_IMAGE::m_LocalRotation, GERBER_FILE_IMAGE::m_MD5_value, GERBER_FILE_IMAGE::m_MirrorA, GERBER_FILE_IMAGE::m_MirrorB, GBR_NETLIST_METADATA::m_NetAttribType, GERBER_FILE_IMAGE::m_NetAttributeDict, GBR_NETLIST_METADATA::m_Netname, GERBER_FILE_IMAGE::m_NoTrailingZeros, GERBER_FILE_IMAGE::m_Offset, GBR_NETLIST_METADATA::m_Padname, GERBER_FILE_IMAGE::m_PartString, GERBER_FILE_IMAGE::m_Relative, D_CODE::m_Rotation, GERBER_FILE_IMAGE::m_Scale, D_CODE::m_Shape, D_CODE::m_Size, GERBER_LAYER::m_StepForRepeat, GERBER_LAYER::m_StepForRepeatMetric, GERBER_FILE_IMAGE::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, GERBER_FILE_IMAGE::ReadApertureMacro(), ReadDouble(), ReadInt(), ReadXCommand(), REMOVE_APERTURE_ATTRIBUTE, GERBER_FILE_IMAGE::RemoveAttribute(), ROTATE, SCALE_FACTOR, D_CODE::SetMacro(), STEP_AND_REPEAT, TO_UTF8, wxPoint::x, and wxPoint::y.

Referenced by GERBER_FILE_IMAGE::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  /* input example: %ADD30R,0.081800X0.101500*%
737  * Aperture definition has 4 options: C, R, O, P
738  * (Circle, Rect, Oval, regular Polygon)
739  * and shapes can have a hole (round or rectangular).
740  * All optional parameters values start by X
741  * at this point, text points to 2nd 'D'
742  */
743  if( *text++ != 'D' )
744  {
745  ok = false;
746  break;
747  }
748 
749  m_Has_DCode = true;
750 
751  code = ReadInt( text );
752 
753  D_CODE* dcode;
754  dcode = GetDCODE( code );
755 
756  if( dcode == NULL )
757  break;
758 
760 
761  // at this point, text points to character after the ADD<num>,
762  // i.e. R in example above. If text[0] is one of the usual
763  // apertures: (C,R,O,P), there is a comma after it.
764  if( text[1] == ',' )
765  {
766  char stdAperture = *text;
767 
768  text += 2; // skip "C," for example
769 
770  dcode->m_Size.x = KiROUND( ReadDouble( text ) * conv_scale );
771  dcode->m_Size.y = dcode->m_Size.x;
772 
773  switch( stdAperture ) // Aperture desceiption has optional parameters. Read them
774  {
775  case 'C': // Circle
776  dcode->m_Shape = APT_CIRCLE;
777  while( *text == ' ' )
778  text++;
779 
780  if( *text == 'X' )
781  {
782  text++;
783  dcode->m_Drill.x = dcode->m_Drill.y =
784  KiROUND( ReadDouble( text ) * conv_scale );
786  }
787 
788  while( *text == ' ' )
789  text++;
790 
791  if( *text == 'X' )
792  {
793  text++;
794  dcode->m_Drill.y =
795  KiROUND( ReadDouble( text ) * conv_scale );
796 
798  }
799  dcode->m_Defined = true;
800  break;
801 
802  case 'O': // oval
803  case 'R': // rect
804  dcode->m_Shape = (stdAperture == 'O') ? APT_OVAL : APT_RECT;
805 
806  while( *text == ' ' )
807  text++;
808 
809  if( *text == 'X' )
810  {
811  text++;
812  dcode->m_Size.y =
813  KiROUND( ReadDouble( text ) * conv_scale );
814  }
815 
816  while( *text == ' ' )
817  text++;
818 
819  if( *text == 'X' )
820  {
821  text++;
822  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
823  dcode->m_Drill.y = dcode->m_Drill.x;
825  }
826 
827  while( *text == ' ' )
828  text++;
829 
830  if( *text == 'X' )
831  {
832  text++;
833  dcode->m_Drill.y =
834  KiROUND( ReadDouble( text ) * conv_scale );
836  }
837  dcode->m_Defined = true;
838  break;
839 
840  case 'P':
841 
842  /* Regular polygon: a command line like %ADD12P,0.040X10X25X0.025X0.025X0.0150*%
843  * params are: <diameter>, X<edge count>, X<Rotation>, X<X hole dim>, X<Y hole dim>
844  */
845  dcode->m_Shape = APT_POLYGON;
846  while( *text == ' ' )
847  text++;
848 
849  if( *text == 'X' )
850  {
851  text++;
852  dcode->m_EdgesCount = ReadInt( text );
853  }
854 
855  while( *text == ' ' )
856  text++;
857 
858  if( *text == 'X' )
859  {
860  text++;
861  dcode->m_Rotation = ReadDouble( text );
862  }
863 
864  while( *text == ' ' )
865  text++;
866 
867  if( *text == 'X' )
868  {
869  text++;
870  dcode->m_Drill.x = KiROUND( ReadDouble( text ) * conv_scale );
871  dcode->m_Drill.y = dcode->m_Drill.x =
873  }
874 
875  while( *text == ' ' )
876  text++;
877 
878  if( *text == 'X' )
879  {
880  text++;
881  dcode->m_Drill.y = KiROUND( ReadDouble( text ) * conv_scale );
883  }
884  dcode->m_Defined = true;
885  break;
886  }
887  }
888  else // text[0] starts an aperture macro name
889  {
890  APERTURE_MACRO am_lookup;
891 
892  while( *text && *text != '*' && *text != ',' )
893  am_lookup.name.Append( *text++ );
894 
895  // When an aperture definition is like %AMLINE2* 22,1,$1,$2,0,0,-45*
896  // the ADDxx<MACRO_NAME> command has parameters, like %ADD14LINE2,0.8X0.5*%
897  if( *text == ',' )
898  { // Read aperture macro parameters and store them
899  text++; // text points the first parameter
900 
901  while( *text && *text != '*' )
902  {
903  double param = ReadDouble( text );
904  dcode->AppendParam( param );
905 
906  while( isspace( *text ) )
907  text++;
908 
909  // Skip 'X' separator:
910  if( *text == 'X' || *text == 'x' )
911  text++;
912  }
913  }
914 
915  // lookup the aperture macro here.
916  APERTURE_MACRO* pam = FindApertureMacro( am_lookup );
917 
918  if( !pam )
919  {
920  msg.Printf( wxT( "RS274X: aperture macro %s not found\n" ),
921  TO_UTF8( am_lookup.name ) );
922  AddMessageToList( msg );
923  ok = false;
924  break;
925  }
926 
927  dcode->m_Shape = APT_MACRO;
928  dcode->SetMacro( pam );
929  }
930 
931  break;
932 
933  default:
934  ok = false;
935  break;
936  }
937 
938  (void) seq_len; // quiet g++, or delete the unused variable.
939 
940  ok = GetEndOfBlock( buff, text, m_Current_File );
941 
942  return ok;
943 }
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:1008
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:946
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)
inherited

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 GERBER_FILE_IMAGE::m_aperture_macros.

Referenced by GERBER_FILE_IMAGE::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)
inherited

Definition at line 413 of file rs274d.cpp.

References IsNumber.

Referenced by GERBER_FILE_IMAGE::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 
)
inherited

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 GERBER_FILE_IMAGE::m_Aperture_List.

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command(), Execute_Drill_Command(), GERBER_FILE_IMAGE::Execute_G_Command(), GERBER_FILE_IMAGE::ExecuteRS274XCommand(), GERBER_DRAW_ITEM::GetDcodeDescr(), GERBVIEW_FRAME::Liste_D_Codes(), readToolInformation(), 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 ( )
inherited
Returns
the count of Dcode tools in used by the image

Definition at line 249 of file class_gerber_file_image.cpp.

References DIM, GERBER_FILE_IMAGE::m_Aperture_List, and GERBER_FILE_IMAGE::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_LAYER& GERBER_FILE_IMAGE::GetLayerParams ( )
inlineinherited
const wxArrayString& GERBER_FILE_IMAGE::GetMessages ( ) const
inlineinherited
COLOR4D GERBER_FILE_IMAGE::GetPositiveDrawColor ( ) const
inlineinherited
bool GERBER_FILE_IMAGE::HasNegativeItems ( )
inherited

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 GERBER_FILE_IMAGE::GetItemsList(), GERBER_FILE_IMAGE::m_GraphicLayer, GERBER_FILE_IMAGE::m_hasNegativeItems, GERBER_FILE_IMAGE::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 ( )
inherited

Function InitToolTable.

Definition at line 264 of file class_gerber_file_image.cpp.

References D_CODE::Clear_D_CODE_Data(), FIRST_DCODE, GERBER_FILE_IMAGE::m_Aperture_List, GERBER_FILE_IMAGE::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 EXCELLON_IMAGE::LoadFile ( const wxString &  aFullFileName)

Read and load a drill (EXCELLON format) file.

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

Definition at line 212 of file excellon_read_drill_file.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), GERBER_FILE_IMAGE::ClearMessageList(), dummy(), Execute_Drill_Command(), Execute_EXCELLON_G_Command(), Execute_HEADER_Command(), file_attribute, LINE_READER::Line(), GERBER_FILE_IMAGE::m_Current_File, GERBER_FILE_IMAGE::m_FileFunction, GERBER_FILE_IMAGE::m_FileName, GERBER_FILE_IMAGE::m_IJPos, GERBER_FILE_IMAGE::m_InUse, m_State, X2_ATTRIBUTE::ParseAttribCmd(), READ_HEADER_STATE, GERBER_FILE_IMAGE::ReadIJCoord(), FILE_LINE_READER::ReadLine(), ResetDefaultValues(), Select_Tool(), and StrPurge().

Referenced by GERBVIEW_FRAME::Read_EXCELLON_File().

213 {
214  // Set the default parmeter values:
217 
218  m_Current_File = wxFopen( aFullFileName, wxT( "rt" ) );
219 
220  if( m_Current_File == NULL )
221  return false;
222 
223  m_FileName = aFullFileName;
224 
225  LOCALE_IO toggleIo;
226 
227  // FILE_LINE_READER will close the file.
228  FILE_LINE_READER excellonReader( m_Current_File, m_FileName );
229 
230  while( true )
231  {
232  if( excellonReader.ReadLine() == 0 )
233  break;
234 
235  char* line = excellonReader.Line();
236  char* text = StrPurge( line );
237 
238  if( *text == ';' ) // comment: skip line
239  continue;
240 
242  {
243  Execute_HEADER_Command( text );
244  }
245  else
246  {
247  switch( *text )
248  {
249  case 'M':
250  Execute_HEADER_Command( text );
251  break;
252 
253  case 'G': /* Line type Gxx : command */
255  break;
256 
257  case 'X':
258  case 'Y': // command like X12550Y19250
259  Execute_Drill_Command(text);
260  break;
261 
262  case 'I':
263  case 'J': /* Auxiliary Move command */
264  m_IJPos = ReadIJCoord( text );
265  if( *text == '*' ) // command like X35142Y15945J504
266  {
267  Execute_Drill_Command( text);
268  }
269  break;
270 
271  case 'T': // Tool command
272  Select_Tool( text );
273  break;
274 
275  case '%':
276  break;
277 
278  default:
279  {
280  wxString msg;
281  msg.Printf( wxT( "Unexpected symbol &lt;%c&gt;" ), *text );
282  AddMessageToList( msg );
283  }
284  break;
285  } // End switch
286  }
287  }
288 
289  // Add our file attribute, to identify the drill file
291  char* text = (char*)file_attribute;
292  dummy.ParseAttribCmd( m_Current_File, NULL, 0, text );
293  delete m_FileFunction;
295 
296  m_InUse = true;
297 
298  return true;
299 }
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 ...
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
virtual void ResetDefaultValues() override
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
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.
bool Select_Tool(char *&text)
bool Execute_HEADER_Command(char *&text)
Class FILE_LINE_READER is a LINE_READER that reads from an open file.
Definition: richio.h:180
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 Execute_Drill_Command(char *&text)
excellon_state m_State
static const char file_attribute[]
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...
bool Execute_EXCELLON_G_Command(char *&text)
bool GERBER_FILE_IMAGE::LoadGerberFile ( const wxString &  aFullFileName)
inherited

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 GERBER_FILE_IMAGE::AddMessageToList(), GERBER_FILE_IMAGE::ClearMessageList(), CMD_IDLE, GERBER_FILE_IMAGE::DCodeNumber(), END_BLOCK, ENTER_RS274X_CMD, GERBER_FILE_IMAGE::Execute_DCODE_Command(), GERBER_FILE_IMAGE::Execute_G_Command(), GERBER_FILE_IMAGE::GCodeNumber(), GERBER_BUFZ, GERBER_FILE_IMAGE::m_CommandState, GERBER_FILE_IMAGE::m_Current_File, GERBER_FILE_IMAGE::m_CurrentPos, GERBER_FILE_IMAGE::m_FileName, GERBER_FILE_IMAGE::m_FilesList, GERBER_FILE_IMAGE::m_FilesPtr, GERBER_FILE_IMAGE::m_IJPos, GERBER_FILE_IMAGE::m_InUse, GERBER_FILE_IMAGE::m_Last_Pen_Command, GERBER_FILE_IMAGE::ReadIJCoord(), GERBER_FILE_IMAGE::ReadRS274XCommand(), GERBER_FILE_IMAGE::ReadXYCoord(), GERBER_FILE_IMAGE::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: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 
)
inherited

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 1008 of file rs274x.cpp.

References GERBER_FILE_IMAGE::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(), GERBER_FILE_IMAGE::m_aperture_macros, GERBER_FILE_IMAGE::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 GERBER_FILE_IMAGE::ExecuteRS274XCommand().

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

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(), GERBER_FILE_IMAGE::m_FmtLen, GERBER_FILE_IMAGE::m_FmtScale, GERBER_FILE_IMAGE::m_GerbMetric, GERBER_FILE_IMAGE::m_IJPos, GERBER_FILE_IMAGE::m_NoTrailingZeros, scale_list, wxPoint::x, and wxPoint::y.

Referenced by LoadFile(), and GERBER_FILE_IMAGE::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 
)
inherited

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

Definition at line 192 of file rs274x.cpp.

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

Referenced by GERBER_FILE_IMAGE::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
bool EXCELLON_IMAGE::readToolInformation ( char *&  aText)
private

Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list.

Definition at line 463 of file excellon_read_drill_file.cpp.

References GERBER_FILE_IMAGE::AddMessageToList(), APT_CIRCLE, FIRST_DCODE, Format(), GERBER_FILE_IMAGE::GetDCODE(), KiROUND(), D_CODE::m_Defined, GERBER_FILE_IMAGE::m_GerbMetric, GERBER_FILE_IMAGE::m_Has_DCode, D_CODE::m_Shape, D_CODE::m_Size, ReadDouble(), and ReadInt().

Referenced by Execute_HEADER_Command(), and Select_Tool().

464 {
465  // Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00
466  // and enter the TCODE param in list (using the D_CODE param management, which
467  // is similar to TCODE params.
468  if( *aText == 'T' ) // This is the beginning of the definition
469  aText++;
470 
471  // Read tool number:
472  int iprm = ReadInt( aText, false );
473 
474  // Skip Feed rate and Spindle speed, if any here
475  while( *aText && ( *aText == 'F' || *aText == 'S' ) )
476  {
477  aText++;
478  ReadInt( aText, false );
479  }
480 
481  // Read tool shape
482  if( ! *aText )
484  _( "Tool definition shape not found" ) ) );
485  else if( *aText != 'C' )
487  _( "Tool definition '%c' not supported" ), *aText ) );
488  if( *aText )
489  aText++;
490 
491  //read tool diameter:
492  double dprm = ReadDouble( aText, false );
493  m_Has_DCode = true;
494 
495  // Initialize Dcode to handle this Tool
496  // Remember: dcodes are >= FIRST_DCODE
497  D_CODE* dcode = GetDCODE( iprm + FIRST_DCODE );
498 
499  if( dcode == NULL )
500  return false;
501 
502  // conv_scale = scaling factor from inch to Internal Unit
503  double conv_scale = IU_PER_MILS * 1000;
504 
505  if( m_GerbMetric )
506  conv_scale /= 25.4;
507 
508  dcode->m_Size.x = dcode->m_Size.y = KiROUND( dprm * conv_scale );
509  dcode->m_Shape = APT_CIRCLE;
510  dcode->m_Defined = true;
511 
512  return true;
513 }
void AddMessageToList(const wxString &aMessage)
Function AddMessageToList Add a message to the message list.
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
wxSize m_Size
Horizontal and vertical dimensions.
Definition: dcode.h:98
APERTURE_T m_Shape
shape ( Line, rectangle, circle , oval .. )
Definition: dcode.h:99
D_CODE * GetDCODE(int aDCODE, bool aCreateIfNoExist=true)
Function GetDCODE returns a pointer to the D_CODE within this GERBER for the given aDCODE...
bool m_Defined
false if the aperture is not defined in the header
Definition: dcode.h:108
#define FIRST_DCODE
Definition: dcode.h:70
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
double ReadDouble(char *&text, bool aSkipSeparator=true)
Function ReadDouble reads a double from an ASCII character buffer.
int ReadInt(char *&text, bool aSkipSeparator=true)
Function ReadInt reads an int from an ASCII character buffer.
wxPoint GERBER_FILE_IMAGE::ReadXYCoord ( char *&  Text)
inherited

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(), GERBER_FILE_IMAGE::m_CurrentPos, GERBER_FILE_IMAGE::m_DecimalFormat, GERBER_FILE_IMAGE::m_FmtLen, GERBER_FILE_IMAGE::m_FmtScale, GERBER_FILE_IMAGE::m_GerbMetric, GERBER_FILE_IMAGE::m_NoTrailingZeros, GERBER_FILE_IMAGE::m_Relative, scale_list, wxPoint::x, and wxPoint::y.

Referenced by Execute_Drill_Command(), Execute_EXCELLON_G_Command(), and GERBER_FILE_IMAGE::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)
inherited

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(), GERBER_FILE_IMAGE::m_AperFunction, and GERBER_FILE_IMAGE::m_NetAttributeDict.

Referenced by GERBER_FILE_IMAGE::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 ...
virtual void EXCELLON_IMAGE::ResetDefaultValues ( )
inlineoverridevirtual

Reimplemented from GERBER_FILE_IMAGE.

Definition at line 110 of file class_excellon.h.

References GERBER_FILE_IMAGE::ResetDefaultValues(), and SelectUnits().

Referenced by LoadFile().

111  {
113  SelectUnits( false );
114  }
void SelectUnits(bool aMetric)
bool EXCELLON_IMAGE::Select_Tool ( char *&  text)
private

Definition at line 578 of file excellon_read_drill_file.cpp.

References FIRST_DCODE, GERBER_FILE_IMAGE::GetDCODE(), GERBER_FILE_IMAGE::m_Current_Tool, D_CODE::m_InUse, readToolInformation(), TCodeNumber(), and TOOLS_MAX_COUNT.

Referenced by LoadFile().

579 {
580  // Select the tool from the command line Tn, with n = 1 ... TOOLS_MAX_COUNT - 1
581  // Because some drill file have an embedded TCODE definition (like T1C.008F0S0)
582  // in tool selection command, if the tool is not defined in list,
583  // and the definition is embedded, it will be entered in list
584  char * startline = text; // the tool id starts here.
585  int tool_id = TCodeNumber( text );
586 
587  // T0 is legal, but is not a selection tool. it is a special command
588  if( tool_id >= 0 )
589  {
590  int dcode_id = tool_id + FIRST_DCODE; // Remember: dcodes are >= FIRST_DCODE
591 
592  if( dcode_id > (TOOLS_MAX_COUNT - 1) )
593  dcode_id = TOOLS_MAX_COUNT - 1;
594 
595  m_Current_Tool = dcode_id;
596  D_CODE* currDcode = GetDCODE( dcode_id , false );
597 
598  if( currDcode == NULL && tool_id > 0 ) // if the definition is embedded, enter it
599  {
600  text = startline; // text starts at the beginning of the command
601  readToolInformation( text );
602  currDcode = GetDCODE( dcode_id , false );
603  }
604 
605  if( currDcode )
606  currDcode->m_InUse = true;
607  }
608 
609  while( *text )
610  text++;
611 
612  return tool_id >= 0;
613 }
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...
#define FIRST_DCODE
Definition: dcode.h:70
int TCodeNumber(char *&aText)
bool readToolInformation(char *&aText)
Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list...
Class D_CODE holds a gerber DCODE (also called Aperture) definition.
Definition: dcode.h:81
#define TOOLS_MAX_COUNT
Definition: dcode.h:72
void EXCELLON_IMAGE::SelectUnits ( bool  aMetric)
private

Definition at line 697 of file excellon_read_drill_file.cpp.

References fmtIntegerInch, fmtIntegerMM, fmtMantissaInch, fmtMantissaMM, GERBER_FILE_IMAGE::m_FmtLen, GERBER_FILE_IMAGE::m_FmtScale, and GERBER_FILE_IMAGE::m_GerbMetric.

Referenced by Execute_HEADER_Command(), and ResetDefaultValues().

698 {
699  /* Coordinates are measured either in inch or metric (millimeters).
700  * Inch coordinates are in six digits (00.0000) with increments
701  * as small as 0.0001 (1/10,000).
702  * Metric coordinates can be measured in microns (thousandths of a millimeter)
703  * in one of the following three ways:
704  * Five digit 10 micron resolution (000.00)
705  * Six digit 10 micron resolution (0000.00)
706  * Six digit micron resolution (000.000)
707  *
708  * Inches: Default fmt = 2.4 for X and Y axis: 6 digits with 0.0001 resolution
709  * metric: Default fmt = 3.3 for X and Y axis: 6 digits, 1 micron resolution
710  */
711  if( aMetric )
712  {
713  m_GerbMetric = true;
714  // number of digits in mantissa
716  // number of digits (mantissa+interger)
718  }
719  else
720  {
721  m_GerbMetric = false;
724  }
725 }
static const int fmtMantissaInch
static const int fmtIntegerInch
static const int fmtMantissaMM
static const int fmtIntegerMM
void GERBER_FILE_IMAGE::StepAndRepeatItem ( const GERBER_DRAW_ITEM aItem)
inherited

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(), GERBER_FILE_IMAGE::GetLayerParams(), GERBER_FILE_IMAGE::m_Drawings, GERBER_LAYER::m_XRepeatCount, GERBER_LAYER::m_YRepeatCount, GERBER_DRAW_ITEM::MoveXY(), scaletoIU(), wxPoint::x, and wxPoint::y.

Referenced by GERBER_FILE_IMAGE::Execute_DCODE_Command(), Execute_Drill_Command(), and GERBER_FILE_IMAGE::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.
int EXCELLON_IMAGE::TCodeNumber ( char *&  aText)
inlineprivate

Definition at line 137 of file class_excellon.h.

References GERBER_FILE_IMAGE::DCodeNumber().

Referenced by Select_Tool().

138  {
139  return DCodeNumber( aText );
140  }
int DCodeNumber(char *&Text)
Definition: rs274d.cpp:436

Member Data Documentation

bool GERBER_FILE_IMAGE::m_360Arc_enbl
inherited
wxString GERBER_FILE_IMAGE::m_AperFunction
inherited
APERTURE_MACRO_SET GERBER_FILE_IMAGE::m_aperture_macros
inherited

a collection of APERTURE_MACROS, sorted by name

Definition at line 162 of file class_gerber_file_image.h.

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

int GERBER_FILE_IMAGE::m_CommandState
inherited
std::map<wxString, int> GERBER_FILE_IMAGE::m_ComponentsList
inherited
bool GERBER_FILE_IMAGE::m_DecimalFormat
inherited
int GERBER_FILE_IMAGE::m_FilesPtr
inherited
bool GERBER_FILE_IMAGE::m_ImageJustifyXCenter
inherited
bool GERBER_FILE_IMAGE::m_ImageJustifyYCenter
inherited
bool GERBER_FILE_IMAGE::m_IsVisible
inherited
bool GERBER_FILE_IMAGE::m_IsX2_file
inherited
int GERBER_FILE_IMAGE::m_Last_Pen_Command
inherited
double GERBER_FILE_IMAGE::m_LocalRotation
inherited
wxString GERBER_FILE_IMAGE::m_MD5_value
inherited
bool GERBER_FILE_IMAGE::m_MirrorA
inherited
bool GERBER_FILE_IMAGE::m_MirrorB
inherited
std::map<wxString, int> GERBER_FILE_IMAGE::m_NetnamesList
inherited
wxString GERBER_FILE_IMAGE::m_PartString
inherited
int GERBER_FILE_IMAGE::m_PolygonFillModeState
inherited
COLOR4D GERBER_FILE_IMAGE::m_PositiveDrawColor
inherited
wxPoint GERBER_FILE_IMAGE::m_PreviousPos
inherited
wxRealPoint GERBER_FILE_IMAGE::m_Scale
inherited
bool EXCELLON_IMAGE::m_SlotOn
private

Definition at line 98 of file class_excellon.h.

Referenced by Execute_Drill_Command(), and Execute_EXCELLON_G_Command().

excellon_state EXCELLON_IMAGE::m_State
private

Definition at line 97 of file class_excellon.h.

Referenced by Execute_HEADER_Command(), and LoadFile().

bool GERBER_FILE_IMAGE::m_SwapAxis
inherited

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