KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef EXCELLON_IMAGE_H
22#define EXCELLON_IMAGE_H
23
25
26
60
61
75
76// Helper struct to analyze 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 command is used)
94 int m_cy; // center y coordinate in circular routing mode
95 // (when the IJ command 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
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 VECTOR2I& aPos, const VECTOR2I& 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 VECTOR2I& 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 VECTOR2I GetPos() { return VECTOR2I( m_x, m_y ); }
124};
125
134{
135public: EXCELLON_IMAGE( int layer ) :
136 GERBER_FILE_IMAGE( layer )
137 {
139 m_SlotOn = false;
140 m_RouteModeOn = false;
141 m_hasFormat = false;
142 }
143
144
146
150 virtual void ResetDefaultValues() override;
151
152
161 static bool TestFileIsExcellon( const wxString& aFullFileName );
162
172 bool LoadFile( const wxString& aFullFileName, EXCELLON_DEFAULTS* aDefaults );
173
174private:
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
186 void readFileFormat( char*& aText );
187
192 bool readToolInformation( char*& aText );
193
197 void FinishRouteCommand();
198
202 void SelectUnits( bool aMetric, EXCELLON_DEFAULTS* aDefaults );
203
204private:
206 READ_HEADER_STATE, // When we are in this state, we are reading header
207 READ_PROGRAM_STATE // When we are in this state, we are reading drill data
208 };
209
210 EXCELLON_STATE m_State; // state of excellon file analysis
211 bool m_SlotOn; // true during an oblong drill definition
212 // by G85 (canned slot) command
213 bool m_RouteModeOn; // true during a route mode (for instance a oval hole) or
214 // a cutout.
215 std::vector<EXCELLON_ROUTE_COORD> m_RoutePositions; // The list of points in a route mode
216
222};
223
224
225/*
226 * EXCELLON commands are given here.
227 * Pcbnew uses only few excellon commands
228 */
229
230/*
231 * see http://www.excellon.com/manuals/program.htm
232 */
233
234/* coordinates units:
235 * Coordinates are measured either in inch or metric (millimeters).
236 * Inch coordinates are in six digits (00.0000) with increments as small as 0.0001 (1/10,000).
237 * Metric coordinates can be measured in microns (thousandths of a millimeter)
238 * in one of the following three ways:
239 * Five digit 10 micron resolution (000.00)
240 * Six digit 10 micron resolution (0000.00)
241 * Six digit micron resolution (000.000)
242 *
243 * Leading and trailing zeros:
244 * Excellon (CNC-7) uses inches in six digits and metric in five or six digits.
245 * The zeros to the left of the coordinate are called leading zeros (LZ).
246 * The zeros to right of the coordinate are called trailing zeros (TZ).
247 * The CNC-7 uses leading zeros unless you specify otherwise through a part program.
248 * You can do so with the INCH/METRIC command.
249 * With leading zeros, the leading zeros must always be included.
250 * Trailing zeros are unneeded and may be left off.
251 * For trailing zeros, the reverse of the above is true.
252 */
253
254/*
255 * EXCELLON Commands Used in a Header
256 * The following table provides you with a list of commands which
257 * are the most used in a part program header.
258 * COMMAND DESCRIPTION
259 * AFS Automatic Feeds and Speeds
260 * ATC Automatic Tool Change
261 * BLKD Delete all Blocks starting with a slash (/)
262 * CCW Clockwise or Counter-clockwise Routing
263 * CP Cutter Compensation
264 * DETECT Broken Tool Detection
265 * DN Down Limit Set
266 * DTMDIST Maximum Rout Distance Before Toolchange
267 * EXDA Extended Drill Area
268 * FMAT Format 1 or 2
269 * FSB Turns the Feed/Speed Buttons off
270 * HPCK Home Pulse Check
271 * ICI Incremental Input of Part Program Coordinates
272 * INCH Measure Everything in Inches
273 * METRIC Measure Everything in Metric
274 * M48 Beginning of Part Program Header
275 * M95 End of Header
276 * NCSL NC Slope Enable/Disable
277 * OM48 Override Part Program Header
278 * OSTOP Optional Stop Switch
279 * OTCLMP Override Table Clamp
280 * PCKPARAM Set up pecking tool,depth,infeed and retract parameters
281 * PF Floating Pressure Foot Switch
282 * PPR Programmable Plunge Rate Enable
283 * PVS Pre-vacuum Shut-off Switch
284 * R,C Reset Clocks
285 * R,CP Reset Program Clocks
286 * R,CR Reset Run Clocks
287 * R,D Reset All Cutter Distances
288 * R,H Reset All Hit Counters
289 * R,T Reset Tool Data
290 * SBK Single Block Mode Switch
291 * SG Spindle Group Mode
292 * SIXM Input From External Source
293 * T Tool Information
294 * TCST Tool Change Stop
295 * UP Upper Limit Set
296 * VER Selection of X and Y Axis Version
297 * Z Zero Set
298 * ZA Auxiliary Zero
299 * ZC Zero Correction
300 * ZS Zero Preset
301 * Z+# or Z-# Set Depth Offset
302 * % Rewind Stop
303 * #/#/# Link Tool for Automatic Tool Change
304 * / Clear Tool Linking
305 */
306
307/*
308 * Beyond The Header: The Part Program Body
309 * COMMAND DESCRIPTION
310 * A# Arc Radius
311 * B# Retract Rate
312 * C# Tool Diameter
313 * F# Table Feed Rate;Z Axis Infeed Rate
314 * G00X#Y# Route Mode; XY is the starting point
315 * G01X#Y# Linear (Straight Line) Route Mode YX is the ending point
316 * G02X#Y#... Circular CW Mode. Radius value (A#) or Center position (I#J#) follows
317 * G03X#Y#... Circular CCW Mode. Radius value (A#) or Center position (I#J#) follows
318 * G04X# Variable Dwell
319 * G05 Drill Mode
320 * G07 Override current tool feed or speed
321 * G32X#Y#A# Routed Circle Canned Cycle
322 * CW G33X#Y#A# Routed Circle Canned Cycle
323 * CCW G34,#(,#) Select Vision Tool
324 * G35(X#Y#) Single Point Vision Offset (Relative to Work Zero)
325 * G36(X#Y#) Multipoint Vision Translation (Relative to Work Zero)
326 * G37 Cancel Vision Translation or Offset (From G35 or G36)
327 * G38(X#Y#) Vision Corrected Single Hole Drilling (Relative to Work Zero)
328 * G39(X#Y#) Vision System Autocalibration
329 * G40 Cutter Compensation Off
330 * G41 Cutter Compensation Left
331 * G42 Cutter Compensation Right
332 * G45(X#Y#) Single Point Vision Offset (Relative to G35 or G36)
333 * G46(X#Y#) Multipoint Vision Translation (Relative to G35 or G36)
334 * G47 Cancel Vision Translation or Offset (From G45 or G46)
335 * G48(X#Y#) Vision Corrected Single Hole Drilling (Relative to G35 or G36)
336 * G82(G81) Dual In Line Package
337 * G83 Eight Pin L Pack
338 * G84 Circle
339 * G85 Slot
340 * G87 Routed Step Slot Canned Cycle
341 * G90 Absolute Mode
342 * G91 Incremental Input Mode
343 * G93X#Y# Zero Set
344 * H# Maximum hit count
345 * I#J# Arc Center Offset
346 * M00(X#Y#) End of Program - No Rewind
347 * M01 End of Pattern
348 * M02X#Y# Repeat Pattern Offset
349 * M06(X#Y#) Optional Stop
350 * M08 End of Step and Repeat
351 * M09(X#Y#) Stop for Inspection
352 * M14 Z Axis Route Position With Depth Controlled Contouring
353 * M15 Z Axis Route Position
354 * M16 Retract With Clamping
355 * M17 Retract Without Clamping
356 * M18 Command tool tip check
357 * M25 Beginning of Pattern
358 * M30(X#Y#) End of Program Rewind
359 * M45,long message\ Long Operator message on multiple\ part program lines
360 * M47,text Operator Message
361 * M50,# Vision Step and Repeat Pattern Start
362 * M51,# Vision Step and Repeat Rewind
363 * M52(#) Vision Step and Repeat Offset Counter Control
364 * M02XYM70 Swap Axes
365 * M60 Reference Scaling enable
366 * M61 Reference Scaling disable
367 * M62 Turn on peck drilling
368 * M63 Turn off peck drilling
369 * M71 Metric Measuring Mode
370 * M72 Inch Measuring Mode
371 * M02XYM80 Mirror Image X Axis
372 * M02XYM90 Mirror Image Y Axis
373 * M97,text Canned Text
374 * M98,text Canned Text
375 * M99,subprogram User Defined Stored Pattern
376 * P#X#(Y#) Repeat Stored Pattern
377 * R#M02X#Y# Repeat Pattern (S&R)
378 * R#(X#Y#) Repeat Hole
379 * S# Spindle RPM
380 * T# Tool Selection; Cutter Index
381 * Z+# or Z-# Depth Offset
382 * % Beginning of Pattern (see M25 command)
383 * / Block Delete
384 */
385
386/*
387 * Example of a Header
388 * COMMAND PURPOSE
389 * M48 The beginning of a header
390 * INCH,LZ Use the inch measuring system with leading zeros
391 * VER,1 Use Version 1 X and Y axis layout
392 * FMAT,2 Use Format 2 commands
393 * 1/2/3 Link tools 1, 2, and 3
394 * T1C.04F200S65 Set Tool 1 for 0.040" with infeed rate of 200 inch/min Speed of 65,000 RPM
395 * DETECT,ON Detect broken tools
396 * M95 End of the header
397 */
398
399#endif // EXCELLON_IMAGE_H
void readFileFormat(char *&aText)
Read an Altium-specific FILE_FORMAT=X:X attribute that specifies the length and mantissa of the numbe...
static bool TestFileIsExcellon(const wxString &aFullFileName)
Performs a heuristics-based check of whether the file is an Excellon drill file.
bool LoadFile(const wxString &aFullFileName, EXCELLON_DEFAULTS *aDefaults)
Read and load a drill (EXCELLON format) file.
bool Execute_Drill_Command(char *&text)
void FinishRouteCommand()
End a route command started by M15 ot G01, G02 or G03 command.
EXCELLON_STATE m_State
bool Execute_HEADER_And_M_Command(char *&text)
bool Execute_EXCELLON_G_Command(char *&text)
bool m_hasFormat
Excellon file do not have a format statement to specify the coordinate format like nn:mm.
bool readToolInformation(char *&aText)
Read a tool definition like T1C0.02 or T1F00S00C0.02 or T1C0.02F00S00 and enter params in TCODE list.
virtual void ResetDefaultValues() override
Set all parameters to a default value, before reading a file.
std::vector< EXCELLON_ROUTE_COORD > m_RoutePositions
bool Select_Tool(char *&text)
void SelectUnits(bool aMetric, EXCELLON_DEFAULTS *aDefaults)
Switch unit selection, and the coordinate format (nn:mm) if not yet set.
EXCELLON_IMAGE(int layer)
drill_G_code_t
@ DRILL_G_CWMOVE
@ DRILL_G_ZERO_SET
@ DRILL_G_INCREMENTAL
@ DRILL_G_ZEROSET
@ DRILL_G_DRILL
@ DRILL_G_LINEARMOVE
@ DRILL_G_ABSOLUTE
@ DRILL_G_SLOT
@ DRILL_G_ROUT
@ DRILL_G_UNKNOWN
@ DRILL_G_CCWMOVE
drill_M_code_t
@ DRILL_M_UNKNOWN
@ DRILL_M_TOOL_UP
@ DRILL_SKIP
@ DRILL_M_ENDPATTERN
@ DRILL_M_TOOL_DOWN
@ DRILL_AUTOMATIC_SPEED
@ DRILL_M_END
@ DRILL_TOOL_CHANGE_STOP
@ DRILL_TOOL_INFORMATION
@ DRILL_AUTOMATIC_TOOL_CHANGE
@ DRILL_M_ENDHEADER
@ DRILL_M_HEADER
@ DRILL_FORMAT_ALTIUM
@ DRILL_M_METRIC
@ DRILL_DETECT_BROKEN
@ DRILL_HEADER_SKIP
@ DRILL_REWIND_STOP
@ DRILL_M_TIPCHECK
@ DRILL_M_LONGMESSAGE
@ DRILL_INCREMENTALHEADER
@ DRILL_AXIS_VERSION
@ DRILL_RESET_CMD
@ DRILL_M_MESSAGE
@ DRILL_METRIC_HEADER
@ DRILL_M_END_LIST
@ DRILL_M_BEGINPATTERN
@ DRILL_IMPERIAL_HEADER
@ DRILL_M_ENDFILE
@ DRILL_FMT
@ DRILL_M_CANNEDTEXT
@ DRILL_M_IMPERIAL
@ ARC_INFO_TYPE_NONE
@ ARC_INFO_TYPE_RADIUS
@ ARC_INFO_TYPE_CENTER
std::string m_Name
management of default values used to read a Excellon (.nc) drill file Some important parameters are n...
EXCELLON_ROUTE_COORD(const VECTOR2I &aPos, const VECTOR2I &aCenter, int aMode)
EXCELLON_ROUTE_COORD(const VECTOR2I &aPos)
EXCELLON_ROUTE_COORD(const VECTOR2I &aPos, int aRadius, int aMode)
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:683