11import { Path , PathType } from './path' ;
22import { Code , GCodeCommand } from './gcode-parser' ;
3- import { Machine } from './machine ' ;
3+ import { Job } from './job ' ;
44
55export class Interpreter {
6- execute ( commands : GCodeCommand [ ] , machine = new Machine ( ) ) : Machine {
6+ execute ( commands : GCodeCommand [ ] , job = new Job ( ) ) : Job {
77 commands . forEach ( ( command ) => {
88 if ( command . code !== undefined ) {
9- this [ command . code ] ( command , machine ) ;
9+ this [ command . code ] ( command , job ) ;
1010 }
1111 } ) ;
1212
13- return machine ;
13+ return job ;
1414 }
1515
16- G0 ( command : GCodeCommand , machine : Machine ) : void {
16+ G0 ( command : GCodeCommand , job : Job ) : void {
1717 const { x, y, z, e } = command . params ;
18- const { state } = machine ;
18+ const { state } = job ;
1919
20- let lastPath = machine . paths [ machine . paths . length - 1 ] ;
20+ let lastPath = job . paths [ job . paths . length - 1 ] ;
2121 const pathType = e ? PathType . Extrusion : PathType . Travel ;
2222
2323 if ( lastPath === undefined || lastPath . travelType !== pathType ) {
24- lastPath = this . breakPath ( machine , pathType ) ;
24+ lastPath = this . breakPath ( job , pathType ) ;
2525 }
2626
2727 state . x = x || state . x ;
@@ -33,17 +33,17 @@ export class Interpreter {
3333
3434 G1 = this . G0 ;
3535
36- G2 ( command : GCodeCommand , machine : Machine ) : void {
36+ G2 ( command : GCodeCommand , job : Job ) : void {
3737 const { x, y, z, e } = command . params ;
3838 let { i, j, r } = command . params ;
39- const { state } = machine ;
39+ const { state } = job ;
4040
4141 const cw = command . code === Code . G2 ;
42- let lastPath = machine . paths [ machine . paths . length - 1 ] ;
42+ let lastPath = job . paths [ job . paths . length - 1 ] ;
4343 const pathType = e ? PathType . Extrusion : PathType . Travel ;
4444
4545 if ( lastPath === undefined || lastPath . travelType !== pathType ) {
46- lastPath = this . breakPath ( machine , pathType ) ;
46+ lastPath = this . breakPath ( job , pathType ) ;
4747 }
4848
4949 if ( r ) {
@@ -130,47 +130,47 @@ export class Interpreter {
130130
131131 G3 = this . G2 ;
132132
133- G28 ( command : GCodeCommand , machine : Machine ) : void {
134- machine . state . x = 0 ;
135- machine . state . y = 0 ;
136- machine . state . z = 0 ;
133+ G28 ( command : GCodeCommand , job : Job ) : void {
134+ job . state . x = 0 ;
135+ job . state . y = 0 ;
136+ job . state . z = 0 ;
137137 }
138138
139- T0 ( command : GCodeCommand , machine : Machine ) : void {
140- machine . state . tool = 0 ;
139+ T0 ( command : GCodeCommand , job : Job ) : void {
140+ job . state . tool = 0 ;
141141 }
142- T1 ( command : GCodeCommand , machine : Machine ) : void {
143- machine . state . tool = 1 ;
142+ T1 ( command : GCodeCommand , job : Job ) : void {
143+ job . state . tool = 1 ;
144144 }
145- T2 ( command : GCodeCommand , machine : Machine ) : void {
146- machine . state . tool = 2 ;
145+ T2 ( command : GCodeCommand , job : Job ) : void {
146+ job . state . tool = 2 ;
147147 }
148- T3 ( command : GCodeCommand , machine : Machine ) : void {
149- machine . state . tool = 3 ;
148+ T3 ( command : GCodeCommand , job : Job ) : void {
149+ job . state . tool = 3 ;
150150 }
151- T4 ( command : GCodeCommand , machine : Machine ) : void {
152- machine . state . tool = 4 ;
151+ T4 ( command : GCodeCommand , job : Job ) : void {
152+ job . state . tool = 4 ;
153153 }
154- T5 ( command : GCodeCommand , machine : Machine ) : void {
155- machine . state . tool = 5 ;
154+ T5 ( command : GCodeCommand , job : Job ) : void {
155+ job . state . tool = 5 ;
156156 }
157- T6 ( command : GCodeCommand , machine : Machine ) : void {
158- machine . state . tool = 6 ;
157+ T6 ( command : GCodeCommand , job : Job ) : void {
158+ job . state . tool = 6 ;
159159 }
160- T7 ( command : GCodeCommand , machine : Machine ) : void {
161- machine . state . tool = 7 ;
160+ T7 ( command : GCodeCommand , job : Job ) : void {
161+ job . state . tool = 7 ;
162162 }
163- G20 ( command : GCodeCommand , machine : Machine ) : void {
164- machine . state . units = 'in' ;
163+ G20 ( command : GCodeCommand , job : Job ) : void {
164+ job . state . units = 'in' ;
165165 }
166- G21 ( command : GCodeCommand , machine : Machine ) : void {
167- machine . state . units = 'mm' ;
166+ G21 ( command : GCodeCommand , job : Job ) : void {
167+ job . state . units = 'mm' ;
168168 }
169169
170- private breakPath ( machine : Machine , newType : PathType ) : Path {
171- const lastPath = new Path ( newType , 0.6 , 0.2 , machine . state . tool ) ;
172- machine . paths . push ( lastPath ) ;
173- lastPath . addPoint ( machine . state . x , machine . state . y , machine . state . z ) ;
170+ private breakPath ( job : Job , newType : PathType ) : Path {
171+ const lastPath = new Path ( newType , 0.6 , 0.2 , job . state . tool ) ;
172+ job . paths . push ( lastPath ) ;
173+ lastPath . addPoint ( job . state . x , job . state . y , job . state . z ) ;
174174 return lastPath ;
175175 }
176176}
0 commit comments