KiCad PCB EDA Suite
excellon_image.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2011-2016 Jean-Pierre Charras jp.charras at wanadoo.fr
5  * Copyright (C) 1992-2016 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef EXCELLON_IMAGE_H
26 #define EXCELLON_IMAGE_H
27 
28 
32  DRILL_M_TOOL_DOWN, // tool down (starting a routed hole)
33  DRILL_M_TOOL_UP, // tool up (ending a routed hole)
58  DRILL_M_END_LIST // not used: sentinel
59 };
60 
61 
63  DRILL_G_UNKNOWN = DRILL_M_END_LIST+1, // Use next available value
74 };
75 
76 // Helper struct to analyse Excellon commands
78 {
79  std::string m_Name; // key string
80  int m_Code; // internal code, used as id in functions
81  int m_asParams; // 0 = no param, -1 = skip params, 1 = read params
82 };
83 
84 // Helper struct to store Excellon points in routing mode
85 #define ROUTE_CCW 1
86 #define ROUTE_CW -1
87 
89 {
90  int m_x; // X coordinate
91  int m_y; // y coordinate
92  int m_cx; // center X coordinate in circular routing mode
93  // (when the IJ commad is used)
94  int m_cy; // center y coordinate in circular routing mode
95  // (when the IJ commad is used)
96  int m_radius; // radius in circular routing mode (when the A## command is used)
97  int m_rmode; // routing mode: 0 = circular, ROUTE_CCW (1) = ccw, ROUTE_CW (-1) = cw
98  int m_arc_type_info; // arc using radius or center coordinates
99 
101  m_x( 0 ), m_y( 0 ), m_cx( 0 ), m_cy( 0 ), m_radius( 0 ),
102  m_rmode( 0 ), m_arc_type_info( 0 )
103  {}
104 
105  EXCELLON_ROUTE_COORD( const wxPoint& aPos ):
106  m_x( aPos.x ), m_y( aPos.y ),
107  m_cx( 0 ), m_cy( 0 ), m_radius( 0 ), m_rmode( 0 ),
109  {}
110 
111  EXCELLON_ROUTE_COORD( const wxPoint& aPos, const wxPoint& aCenter, int aMode ):
112  m_x( aPos.x ), m_y( aPos.y ),
113  m_cx( aCenter.x ), m_cy( aCenter.y ), m_radius( 0 ), m_rmode( aMode ),
115  {}
116 
117  EXCELLON_ROUTE_COORD( const wxPoint& aPos, int aRadius, int aMode ):
118  m_x( aPos.x ), m_y( aPos.y ),
119  m_cx( 0 ), m_cy( 0 ), m_radius( aRadius ), m_rmode( aMode ),
121  {}
122 
123  wxPoint GetPos() { return wxPoint( m_x, m_y ); }
124 };
125 
126 /* EXCELLON_IMAGE handle a drill image
127  * It is derived from GERBER_FILE_IMAGE because there is a lot of likeness
128  * between EXCELLON files and GERBER files
129  * DCode aperture are also similat to T Codes.
130  * So we can reuse GERBER_FILE_IMAGE to handle EXCELLON_IMAGE with very few new functions
131  */
132 
134 {
135 private:
137  READ_HEADER_STATE, // When we are in this state, we are reading header
138  READ_PROGRAM_STATE // When we are in this state, we are reading drill data
139  };
140 
141  excellon_state m_State; // state of excellon file analysis
142  bool m_SlotOn; // true during an oblong drill definition
143  // by G85 (canned slot) command
144  bool m_RouteModeOn; // true during a route mode (for instance a oval hole) or a cutout
145  std::vector<EXCELLON_ROUTE_COORD> m_RoutePositions; // The list of points in a route mode
146 
147 public: EXCELLON_IMAGE( int layer ) :
148  GERBER_FILE_IMAGE( layer )
149  {
151  m_SlotOn = false;
152  m_RouteModeOn = false;
153  }
154 
155 
157 
158  virtual void ResetDefaultValues() override
159  {
161  SelectUnits( false );
162  }
163 
164 
172  bool LoadFile( const wxString& aFullFileName );
173 
174 private:
175  bool Execute_HEADER_And_M_Command( char*& text );
176  bool Select_Tool( char*& text );
177  bool Execute_EXCELLON_G_Command( char*& text );
178  bool Execute_Drill_Command( char*& text );
179 
183  bool readToolInformation( char*& aText );
184 
185  int TCodeNumber( char*& aText )
186  {
187  return DCodeNumber( aText );
188  }
189 
192  void FinishRouteCommand();
193 
194  void SelectUnits( bool aMetric );
195 };
196 
197 
198 /*
199  * EXCELLON commands are given here.
200  * Pcbnew uses only few excellon commands
201  */
202 
203 /*
204  * see http://www.excellon.com/manuals/program.htm
205  */
206 
207 /* coordinates units:
208  * Coordinates are measured either in inch or metric (millimeters).
209  * Inch coordinates are in six digits (00.0000) with increments as small as 0.0001 (1/10,000).
210  * Metric coordinates can be measured in microns (thousandths of a millimeter)
211  * in one of the following three ways:
212  * Five digit 10 micron resolution (000.00)
213  * Six digit 10 micron resolution (0000.00)
214  * Six digit micron resolution (000.000)
215  *
216  * Leading and trailing zeros:
217  * Excellon (CNC-7) uses inches in six digits and metric in five or six digits.
218  * The zeros to the left of the coordinate are called leading zeros (LZ).
219  * The zeros to right of the coordinate are called trailing zeros (TZ).
220  * The CNC-7 uses leading zeros unless you specify otherwise through a part program.
221  * You can do so with the INCH/METRIC command.
222  * With leading zeros, the leading zeros must always be included.
223  * Trailing zeros are unneeded and may be left off.
224  * For trailing zeros, the reverse of the above is true.
225  */
226 
227 /*
228  * EXCELLON Commands Used in a Header
229  * The following table provides you with a list of commands which
230  * are the most used in a part program header.
231  * COMMAND DESCRIPTION
232  * AFS Automatic Feeds and Speeds
233  * ATC Automatic Tool Change
234  * BLKD Delete all Blocks starting with a slash (/)
235  * CCW Clockwise or Counter-clockwise Routing
236  * CP Cutter Compensation
237  * DETECT Broken Tool Detection
238  * DN Down Limit Set
239  * DTMDIST Maximum Rout Distance Before Toolchange
240  * EXDA Extended Drill Area
241  * FMAT Format 1 or 2
242  * FSB Turns the Feed/Speed Buttons off
243  * HPCK Home Pulse Check
244  * ICI Incremental Input of Part Program Coordinates
245  * INCH Measure Everything in Inches
246  * METRIC Measure Everything in Metric
247  * M48 Beginning of Part Program Header
248  * M95 End of Header
249  * NCSL NC Slope Enable/Disable
250  * OM48 Override Part Program Header
251  * OSTOP Optional Stop Switch
252  * OTCLMP Override Table Clamp
253  * PCKPARAM Set up pecking tool,depth,infeed and retract parameters
254  * PF Floating Pressure Foot Switch
255  * PPR Programmable Plunge Rate Enable
256  * PVS Pre-vacuum Shut-off Switch
257  * R,C Reset Clocks
258  * R,CP Reset Program Clocks
259  * R,CR Reset Run Clocks
260  * R,D Reset All Cutter Distances
261  * R,H Reset All Hit Counters
262  * R,T Reset Tool Data
263  * SBK Single Block Mode Switch
264  * SG Spindle Group Mode
265  * SIXM Input From External Source
266  * T Tool Information
267  * TCST Tool Change Stop
268  * UP Upper Limit Set
269  * VER Selection of X and Y Axis Version
270  * Z Zero Set
271  * ZA Auxiliary Zero
272  * ZC Zero Correction
273  * ZS Zero Preset
274  * Z+# or Z-# Set Depth Offset
275  * % Rewind Stop
276  * #/#/# Link Tool for Automatic Tool Change
277  * / Clear Tool Linking
278  */
279 
280 /*
281  * Beyond The Header: The Part Program Body
282  * COMMAND DESCRIPTION
283  * A# Arc Radius
284  * B# Retract Rate
285  * C# Tool Diameter
286  * F# Table Feed Rate;Z Axis Infeed Rate
287  * G00X#Y# Route Mode; XY is the starting point
288  * G01X#Y# Linear (Straight Line) Route Mode YX is the ending point
289  * G02X#Y#... Circular CW Mode. Radius value (A#) or Center position (I#J#) follows
290  * G03X#Y#... Circular CCW Mode. Radius value (A#) or Center position (I#J#) follows
291  * G04 X# Variable Dwell
292  * G05 Drill Mode
293  * G07 Override current tool feed or speed
294  * G32X#Y#A# Routed Circle Canned Cycle
295  * CW G33X#Y#A# Routed Circle Canned Cycle
296  * CCW G34,#(,#) Select Vision Tool
297  * G35(X#Y#) Single Point Vision Offset (Relative to Work Zero)
298  * G36(X#Y#) Multipoint Vision Translation (Relative to Work Zero)
299  * G37 Cancel Vision Translation or Offset (From G35 or G36)
300  * G38(X#Y#) Vision Corrected Single Hole Drilling (Relative to Work Zero)
301  * G39(X#Y#) Vision System Autocalibration
302  * G40 Cutter Compensation Off
303  * G41 Cutter Compensation Left
304  * G42 Cutter Compensation Right
305  * G45(X#Y#) Single Point Vision Offset (Relative to G35 or G36)
306  * G46(X#Y#) Multipoint Vision Translation (Relative to G35 or G36)
307  * G47 Cancel Vision Translation or Offset (From G45 or G46)
308  * G48(X#Y#) Vision Corrected Single Hole Drilling (Relative to G35 or G36)
309  * G82(G81) Dual In Line Package
310  * G83 Eight Pin L Pack
311  * G84 Circle
312  * G85 Slot
313  * G87 Routed Step Slot Canned Cycle
314  * G90 Absolute Mode
315  * G91 Incremental Input Mode
316  * G93X#Y# Zero Set
317  * H# Maximum hit count
318  * I#J# Arc Center Offset
319  * M00(X#Y#) End of Program - No Rewind
320  * M01 End of Pattern
321  * M02X#Y# Repeat Pattern Offset
322  * M06(X#Y#) Optional Stop
323  * M08 End of Step and Repeat
324  * M09(X#Y#) Stop for Inspection
325  * M14 Z Axis Route Position With Depth Controlled Contouring
326  * M15 Z Axis Route Position
327  * M16 Retract With Clamping
328  * M17 Retract Without Clamping
329  * M18 Command tool tip check
330  * M25 Beginning of Pattern
331  * M30(X#Y#) End of Program Rewind
332  * M45,long message\ Long Operator message on multiple\ part program lines
333  * M47,text Operator Message
334  * M50,# Vision Step and Repeat Pattern Start
335  * M51,# Vision Step and Repeat Rewind
336  * M52(#) Vision Step and Repeat Offset Counter Control
337  * M02XYM70 Swap Axes
338  * M60 Reference Scaling enable
339  * M61 Reference Scaling disable
340  * M62 Turn on peck drilling
341  * M63 Turn off peck drilling
342  * M71 Metric Measuring Mode
343  * M72 Inch Measuring Mode
344  * M02XYM80 Mirror Image X Axis
345  * M02XYM90 Mirror Image Y Axis
346  * M97,text Canned Text
347  * M98,text Canned Text
348  * M99,subprogram User Defined Stored Pattern
349  * P#X#(Y#) Repeat Stored Pattern
350  * R#M02X#Y# Repeat Pattern (S&R)
351  * R#(X#Y#) Repeat Hole
352  * S# Spindle RPM
353  * T# Tool Selection; Cutter Index
354  * Z+# or Z-# Depth Offset
355  * % Beginning of Pattern (see M25 command)
356  * / Block Delete
357  */
358 
359 /*
360  * Example of a Header
361  * COMMAND PURPOSE
362  * M48 The beginning of a header
363  * INCH,LZ Use the inch measuring system with leading zeros
364  * VER,1 Use Version 1 X and Y axis layout
365  * FMAT,2 Use Format 2 commands
366  * 1/2/3 Link tools 1, 2, and 3
367  * T1C.04F200S65 Set Tool 1 for 0.040" with infeed rate of 200 inch/min Speed of 65,000 RPM
368  * DETECT,ON Detect broken tools
369  * M95 End of the header
370  */
371 
372 #endif // EXCELLON_IMAGE_H
EXCELLON_ROUTE_COORD(const wxPoint &aPos, const wxPoint &aCenter, int aMode)
virtual void ResetDefaultValues() override
Class GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters ...
bool Select_Tool(char *&text)
bool LoadFile(const wxString &aFullFileName)
Read and load a drill (EXCELLON format) file.
bool Execute_HEADER_And_M_Command(char *&text)
EXCELLON_ROUTE_COORD(const wxPoint &aPos, int aRadius, int aMode)
int DCodeNumber(char *&Text)
Definition: rs274d.cpp:434
bool Execute_Drill_Command(char *&text)
std::string m_Name
EXCELLON_IMAGE(int layer)
excellon_state m_State
int TCodeNumber(char *&aText)
EXCELLON_ROUTE_COORD(const wxPoint &aPos)
bool readToolInformation(char *&aText)
Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list.
drill_M_code_t
void FinishRouteCommand()
Ends a route command started by M15 ot G01, G02 or G03 command.
std::vector< EXCELLON_ROUTE_COORD > m_RoutePositions
bool Execute_EXCELLON_G_Command(char *&text)
void SelectUnits(bool aMetric)
drill_G_code_t
virtual void ResetDefaultValues()