Skip to content

Commit 73a2f0c

Browse files
committed
Rename Machine to Job
1 parent 3e83d28 commit 73a2f0c

File tree

4 files changed

+53
-53
lines changed

4 files changed

+53
-53
lines changed

demo/js/app.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ export const app = (window.app = createApp({
6767
lineWidth,
6868
renderTubes,
6969
extrusionWidth,
70-
virtualMachine
70+
job
7171
} = preview;
7272
const { thumbnails } = parser.metadata;
7373

7474
thumbnail.value = thumbnails['220x124']?.src;
75-
layerCount.value = virtualMachine.layers().length;
75+
layerCount.value = job.layers().length;
7676
const colors = extrusionColor instanceof Array ? extrusionColor : [extrusionColor];
7777
const currentSettings = {
78-
maxLayer: virtualMachine.layers().length,
79-
endLayer: virtualMachine.layers().length,
78+
maxLayer: job.layers().length,
79+
endLayer: job.layers().length,
8080
singleLayerMode,
8181
renderTravel,
8282
travelColor: '#' + travelColor.getHexString(),
@@ -95,7 +95,7 @@ export const app = (window.app = createApp({
9595
};
9696

9797
Object.assign(settings.value, currentSettings);
98-
preview.endLayer = virtualMachine.layers().length;
98+
preview.endLayer = job.layers().length;
9999
};
100100

101101
const loadGCodeFromServer = async (filename) => {

src/interpreter.ts

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
import { Path, PathType } from './path';
22
import { Code, GCodeCommand } from './gcode-parser';
3-
import { Machine } from './machine';
3+
import { Job } from './job';
44

55
export 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
}

src/machine.ts renamed to src/job.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class State {
1515
}
1616
}
1717

18-
export class Machine {
18+
export class Job {
1919
paths: Path[];
2020
state: State;
2121

src/webgl-preview.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Stats from 'three/examples/jsm/libs/stats.module.js';
66

77
import { DevGUI, DevModeOptions } from './dev-gui';
88
import { Interpreter } from './interpreter';
9-
import { Machine } from './machine';
9+
import { Job } from './job';
1010

1111
import {
1212
AmbientLight,
@@ -97,7 +97,7 @@ export class WebGLPreview {
9797
private animationFrameId?: number;
9898
private _geometries: Record<number, BufferGeometry[]> = {};
9999
interpreter: Interpreter = new Interpreter();
100-
virtualMachine: Machine = new Machine();
100+
job: Job = new Job();
101101

102102
// colors
103103
private _backgroundColor = new Color(0xe0e0e0);
@@ -237,7 +237,7 @@ export class WebGLPreview {
237237

238238
processGCode(gcode: string | string[]): void {
239239
const { commands } = this.parser.parseGCode(gcode);
240-
this.interpreter.execute(commands, this.virtualMachine);
240+
this.interpreter.execute(commands, this.job);
241241
this.render();
242242
}
243243

@@ -313,7 +313,7 @@ export class WebGLPreview {
313313
clear(): void {
314314
this.resetState();
315315
this.parser = new Parser();
316-
this.virtualMachine = new Machine();
316+
this.job = new Job();
317317
}
318318

319319
// reset processing state
@@ -353,7 +353,7 @@ export class WebGLPreview {
353353
const material = new LineBasicMaterial({ color: this._travelColor, linewidth: this.lineWidth });
354354
this.disposables.push(material);
355355

356-
this.virtualMachine.travels().forEach((path) => {
356+
this.job.travels().forEach((path) => {
357357
const geometry = path.line();
358358
const line = new LineSegments(geometry, material);
359359
this.group?.add(line);
@@ -374,7 +374,7 @@ export class WebGLPreview {
374374
});
375375
}
376376

377-
this.virtualMachine.extrusions().forEach((path) => {
377+
this.job.extrusions().forEach((path) => {
378378
const geometry = path.line();
379379
const line = new LineSegments(geometry, lineMaterials[path.tool]);
380380
this.group?.add(line);
@@ -386,7 +386,7 @@ export class WebGLPreview {
386386
this._geometries = {};
387387
if (Object.keys(this._geometries).length === 0 && this.renderTubes) {
388388
let color: number;
389-
this.virtualMachine.extrusions().forEach((path) => {
389+
this.job.extrusions().forEach((path) => {
390390
if (Array.isArray(this._extrusionColor)) {
391391
color = this._extrusionColor[path.tool].getHex();
392392
} else {

0 commit comments

Comments
 (0)