summaryrefslogtreecommitdiff
path: root/branches/sm-unittesting/src/org/reprap/machines/NullCartesianMachine.java
blob: 1a294e72a234fbb2b8e44371a05a812b39cc334f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package org.reprap.machines;

import java.io.IOException;
import java.util.Properties;

import org.reprap.CartesianPrinter;
import org.reprap.ReprapException;
import org.reprap.gui.Previewer;

public class NullCartesianMachine implements CartesianPrinter {
	
	private Previewer previewer = null;

	double totalDistanceMoved = 0.0;
	double totalDistanceExtruded = 0.0;
	
	double currentX, currentY, currentZ;
	
	public NullCartesianMachine(Properties config) {
		currentX = 0;
		currentY = 0;
		currentZ = 0;
	}
	
	public void calibrate() {
	}

	public void printSegment(double startX, double startY, double startZ, double endX, double endY, double endZ) throws ReprapException, IOException {
		moveTo(startX, startY, startZ);
		printTo(endX, endY, endZ);
	}

	public void moveTo(double x, double y, double z) throws ReprapException, IOException {
		if (isCancelled()) return;

		totalDistanceMoved += segmentLength(x - currentX, y - currentY);
		if (z != currentZ)
			totalDistanceMoved += Math.abs(currentZ - z);

		currentX = x;
		currentY = y;
		currentZ = z;
	}

	public void printTo(double x, double y, double z) throws ReprapException, IOException {
		if (previewer != null)
			previewer.addSegment(currentX, currentY, currentZ, x, y, z);
		if (isCancelled()) return;

		double distance = segmentLength(x - currentX, y - currentY);
		if (z != currentZ)
			distance += Math.abs(currentZ - z);
		totalDistanceExtruded += distance;
		totalDistanceMoved += distance;
		
		currentX = x;
		currentY = y;
		currentZ = z;
	}

	public void selectMaterial(int materialIndex) {
		if (isCancelled()) return;
		if (previewer != null)
			previewer.setMaterial(materialIndex);
	}

	public void terminate() throws IOException {
	}

	public int getSpeed() {
		return 200;
	}

	public void setSpeed(int speed) {
	}

	public int getExtruderSpeed() {
		return 200;
	}

	public void setExtruderSpeed(int speed) {
	}

	public void setPreviewer(Previewer previewer) {
		this.previewer = previewer;
	}

	public void setTemperature(int temperature) {
	}

	public void dispose() {
	}

	public boolean isCancelled() {
		if (previewer != null)
			return previewer.isCancelled();
		return false;
	}

	public void initialise() {
		if (previewer != null)
			previewer.reset();
	}

	public double getX() {
		return currentX;
	}

	public double getY() {
		return currentY;
	}

	public double getZ() {
		return currentZ;
	}

	/* (non-Javadoc)
	 * @see org.reprap.Printer#getTotalDistanceMoved()
	 */
	public double getTotalDistanceMoved() {
		return totalDistanceMoved;
	}

	/* (non-Javadoc)
	 * @see org.reprap.Printer#getTotalDistanceExtruded()
	 */
	public double getTotalDistanceExtruded() {
		return totalDistanceExtruded;
	}

	public double segmentLength(double x, double y) {
		return Math.sqrt(x*x + y*y);
	}
}