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-2021 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 struct EXCELLON_DEFAULTS;
29 
30 
34  DRILL_M_TOOL_DOWN, // tool down (starting a routed hole)
35  DRILL_M_TOOL_UP, // tool up (ending a routed hole)
62  DRILL_M_END_LIST // not used: sentinel
63 };
64 
65 
67  DRILL_G_UNKNOWN = DRILL_M_END_LIST+1, // Use next available value
78 };
79 
80 // Helper struct to analyze Excellon commands
82 {
83  std::string m_Name; // key string
84  int m_Code; // internal code, used as id in functions
85  int m_asParams; // 0 = no param, -1 = skip params, 1 = read params
86 };
87 
88 // Helper struct to store Excellon points in routing mode
89 #define ROUTE_CCW 1
90 #define ROUTE_CW -1
91 
93 {
94  int m_x; // X coordinate
95  int m_y; // y coordinate
96  int m_cx; // center X coordinate in circular routing mode
97  // (when the IJ command is used)
98  int m_cy; // center y coordinate in circular routing mode
99  // (when the IJ command is used)
100  int m_radius; // radius in circular routing mode (when the A## command is used)
101  int m_rmode; // routing mode: 0 = circular, ROUTE_CCW (1) = ccw, ROUTE_CW (-1) = cw
102  int m_arc_type_info; // arc using radius or center coordinates
103 
105  m_x( 0 ), m_y( 0 ), m_cx( 0 ), m_cy( 0 ), m_radius( 0 ),
106  m_rmode( 0 ), m_arc_type_info( 0 )
107  {}
108 
109  EXCELLON_ROUTE_COORD( const wxPoint& aPos ):
110  m_x( aPos.x ), m_y( aPos.y ),
111  m_cx( 0 ), m_cy( 0 ), m_radius( 0 ), m_rmode( 0 ),
113  {}
114 
115  EXCELLON_ROUTE_COORD( const wxPoint& aPos, const wxPoint& aCenter, int aMode ):
116  m_x( aPos.x ), m_y( aPos.y ),
117  m_cx( aCenter.x ), m_cy( aCenter.y ), m_radius( 0 ), m_rmode( aMode ),
119  {}
120 
121  EXCELLON_ROUTE_COORD( const wxPoint& aPos, int aRadius, int aMode ):
122  m_x( aPos.x ), m_y( aPos.y ),
123  m_cx( 0 ), m_cy( 0 ), m_radius( aRadius ), m_rmode( aMode ),
125  {}
126 
127  wxPoint GetPos() { return wxPoint( m_x, m_y ); }
128 };
129 
138 {
139 public: EXCELLON_IMAGE( int layer ) :
140  GERBER_FILE_IMAGE( layer )
141  {
143  m_SlotOn = false;
144  m_RouteModeOn = false;
145  m_hasFormat = false;
146  }
147 
148 
150 
154  virtual void ResetDefaultValues() override;
155 
156 
166  bool LoadFile( const wxString& aFullFileName, EXCELLON_DEFAULTS* aDefaults );
167 
168 private:
169  bool Execute_HEADER_And_M_Command( char*& text );
170  bool Select_Tool( char*& text );
171  bool Execute_EXCELLON_G_Command( char*& text );
172  bool Execute_Drill_Command( char*& text );
173 
180  void readFileFormat( char*& aText );
181 
186  bool readToolInformation( char*& aText );
187 
188  int TCodeNumber( char*& aText )
189  {
190  return DCodeNumber( aText );
191  }
192 
196  void FinishRouteCommand();
197 
201  void SelectUnits( bool aMetric, EXCELLON_DEFAULTS* aDefaults );
202 
203 private:
205  READ_HEADER_STATE, // When we are in this state, we are reading header
206  READ_PROGRAM_STATE // When we are in this state, we are reading drill data
207  };
208 
209  EXCELLON_STATE m_State; // state of excellon file analysis
210  bool m_SlotOn; // true during an oblong drill definition
211  // by G85 (canned slot) command
212  bool m_RouteModeOn; // true during a route mode (for instance a oval hole) or
213  // a cutout.
214  std::vector<EXCELLON_ROUTE_COORD> m_RoutePositions; // The list of points in a route mode
215 
221 };
222 
223 
224 /*
225  * EXCELLON commands are given here.
226  * Pcbnew uses only few excellon commands
227  */
228 
229 /*
230  * see http://www.excellon.com/manuals/program.htm
231  */
232 
233 /* coordinates units:
234  * Coordinates are measured either in inch or metric (millimeters).
235  * Inch coordinates are in six digits (00.0000) with increments as small as 0.0001 (1/10,000).
236  * Metric coordinates can be measured in microns (thousandths of a millimeter)
237  * in one of the following three ways:
238  * Five digit 10 micron resolution (000.00)
239  * Six digit 10 micron resolution (0000.00)
240  * Six digit micron resolution (000.000)
241  *
242  * Leading and trailing zeros:
243  * Excellon (CNC-7) uses inches in six digits and metric in five or six digits.
244  * The zeros to the left of the coordinate are called leading zeros (LZ).
245  * The zeros to right of the coordinate are called trailing zeros (TZ).
246  * The CNC-7 uses leading zeros unless you specify otherwise through a part program.
247  * You can do so with the INCH/METRIC command.
248  * With leading zeros, the leading zeros must always be included.
249  * Trailing zeros are unneeded and may be left off.
250  * For trailing zeros, the reverse of the above is true.
251  */
252 
253 /*
254  * EXCELLON Commands Used in a Header
255  * The following table provides you with a list of commands which
256  * are the most used in a part program header.
257  * COMMAND DESCRIPTION
258  * AFS Automatic Feeds and Speeds
259  * ATC Automatic Tool Change
260  * BLKD Delete all Blocks starting with a slash (/)
261  * CCW Clockwise or Counter-clockwise Routing
262  * CP Cutter Compensation
263  * DETECT Broken Tool Detection
264  * DN Down Limit Set
265  * DTMDIST Maximum Rout Distance Before Toolchange
266  * EXDA Extended Drill Area
267  * FMAT Format 1 or 2
268  * FSB Turns the Feed/Speed Buttons off
269  * HPCK Home Pulse Check
270  * ICI Incremental Input of Part Program Coordinates
271  * INCH Measure Everything in Inches
272  * METRIC Measure Everything in Metric
273  * M48 Beginning of Part Program Header
274  * M95 End of Header
275  * NCSL NC Slope Enable/Disable
276  * OM48 Override Part Program Header
277  * OSTOP Optional Stop Switch
278  * OTCLMP Override Table Clamp
279  * PCKPARAM Set up pecking tool,depth,infeed and retract parameters
280  * PF Floating Pressure Foot Switch
281  * PPR Programmable Plunge Rate Enable
282  * PVS Pre-vacuum Shut-off Switch
283  * R,C Reset Clocks
284  * R,CP Reset Program Clocks
285  * R,CR Reset Run Clocks
286  * R,D Reset All Cutter Distances
287  * R,H Reset All Hit Counters
288  * R,T Reset Tool Data
289  * SBK Single Block Mode Switch
290  * SG Spindle Group Mode
291  * SIXM Input From External Source
292  * T Tool Information
293  * TCST Tool Change Stop
294  * UP Upper Limit Set
295  * VER Selection of X and Y Axis Version
296  * Z Zero Set
297  * ZA Auxiliary Zero
298  * ZC Zero Correction
299  * ZS Zero Preset
300  * Z+# or Z-# Set Depth Offset
301  * % Rewind Stop
302  * #/#/# Link Tool for Automatic Tool Change
303  * / Clear Tool Linking
304  */
305 
306 /*
307  * Beyond The Header: The Part Program Body
308  * COMMAND DESCRIPTION
309  * A# Arc Radius
310  * B# Retract Rate
311  * C# Tool Diameter
312  * F# Table Feed Rate;Z Axis Infeed Rate
313  * G00X#Y# Route Mode; XY is the starting point
314  * G01X#Y# Linear (Straight Line) Route Mode YX is the ending point
315  * G02X#Y#... Circular CW Mode. Radius value (A#) or Center position (I#J#) follows
316  * G03X#Y#... Circular CCW Mode. Radius value (A#) or Center position (I#J#) follows
317  * G04X# Variable Dwell
318  * G05 Drill Mode
319  * G07 Override current tool feed or speed
320  * G32X#Y#A# Routed Circle Canned Cycle
321  * CW G33X#Y#A# Routed Circle Canned Cycle
322  * CCW G34,#(,#) Select Vision Tool
323  * G35(X#Y#) Single Point Vision Offset (Relative to Work Zero)
324  * G36(X#Y#) Multipoint Vision Translation (Relative to Work Zero)
325  * G37 Cancel Vision Translation or Offset (From G35 or G36)
326  * G38(X#Y#) Vision Corrected Single Hole Drilling (Relative to Work Zero)
327  * G39(X#Y#) Vision System Autocalibration
328  * G40 Cutter Compensation Off
329  * G41 Cutter Compensation Left
330  * G42 Cutter Compensation Right
331  * G45(X#Y#) Single Point Vision Offset (Relative to G35 or G36)
332  * G46(X#Y#) Multipoint Vision Translation (Relative to G35 or G36)
333  * G47 Cancel Vision Translation or Offset (From G45 or G46)
334  * G48(X#Y#) Vision Corrected Single Hole Drilling (Relative to G35 or G36)
335  * G82(G81) Dual In Line Package
336  * G83 Eight Pin L Pack
337  * G84 Circle
338  * G85 Slot
339  * G87 Routed Step Slot Canned Cycle
340  * G90 Absolute Mode
341  * G91 Incremental Input Mode
342  * G93X#Y# Zero Set
343  * H# Maximum hit count
344  * I#J# Arc Center Offset
345  * M00(X#Y#) End of Program - No Rewind
346  * M01 End of Pattern
347  * M02X#Y# Repeat Pattern Offset
348  * M06(X#Y#) Optional Stop
349  * M08 End of Step and Repeat
350  * M09(X#Y#) Stop for Inspection
351  * M14 Z Axis Route Position With Depth Controlled Contouring
352  * M15 Z Axis Route Position
353  * M16 Retract With Clamping
354  * M17 Retract Without Clamping
355  * M18 Command tool tip check
356  * M25 Beginning of Pattern
357  * M30(X#Y#) End of Program Rewind
358  * M45,long message\ Long Operator message on multiple\ part program lines
359  * M47,text Operator Message
360  * M50,# Vision Step and Repeat Pattern Start
361  * M51,# Vision Step and Repeat Rewind
362  * M52(#) Vision Step and Repeat Offset Counter Control
363  * M02XYM70 Swap Axes
364  * M60 Reference Scaling enable
365  * M61 Reference Scaling disable
366  * M62 Turn on peck drilling
367  * M63 Turn off peck drilling
368  * M71 Metric Measuring Mode
369  * M72 Inch Measuring Mode
370  * M02XYM80 Mirror Image X Axis
371  * M02XYM90 Mirror Image Y Axis
372  * M97,text Canned Text
373  * M98,text Canned Text
374  * M99,subprogram User Defined Stored Pattern
375  * P#X#(Y#) Repeat Stored Pattern
376  * R#M02X#Y# Repeat Pattern (S&R)
377  * R#(X#Y#) Repeat Hole
378  * S# Spindle RPM
379  * T# Tool Selection; Cutter Index
380  * Z+# or Z-# Depth Offset
381  * % Beginning of Pattern (see M25 command)
382  * / Block Delete
383  */
384 
385 /*
386  * Example of a Header
387  * COMMAND PURPOSE
388  * M48 The beginning of a header
389  * INCH,LZ Use the inch measuring system with leading zeros
390  * VER,1 Use Version 1 X and Y axis layout
391  * FMAT,2 Use Format 2 commands
392  * 1/2/3 Link tools 1, 2, and 3
393  * T1C.04F200S65 Set Tool 1 for 0.040" with infeed rate of 200 inch/min Speed of 65,000 RPM
394  * DETECT,ON Detect broken tools
395  * M95 End of the header
396  */
397 
398 #endif // EXCELLON_IMAGE_H
EXCELLON_ROUTE_COORD(const wxPoint &aPos, const wxPoint &aCenter, int aMode)
bool LoadFile(const wxString &aFullFileName, EXCELLON_DEFAULTS *aDefaults)
Read and load a drill (EXCELLON format) file.
void SelectUnits(bool aMetric, EXCELLON_DEFAULTS *aDefaults)
Switch unit selection, and the coordinate format (nn:mm) if not yet set.
Hold the image data and parameters for one gerber file and layer parameters.
EXCELLON_STATE m_State
bool Select_Tool(char *&text)
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:422
bool Execute_Drill_Command(char *&text)
bool m_hasFormat
Excellon file do not have a format statement to specify the coordinate format like nn:mm.
std::string m_Name
EXCELLON_IMAGE(int layer)
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.
Handle a drill image.
drill_M_code_t
void readFileFormat(char *&aText)
Read an Altium-specific FILE_FORMAT=X:X attribute that specifies the length and mantissa of the numbe...
virtual void ResetDefaultValues() override
Set all parameters to a default value, before reading a file.
void FinishRouteCommand()
End 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)
management of default values used to read a Excellon (.nc) drill file Some important parameters are n...
drill_G_code_t